Hi guys,
I am trying to use command line arguments to read in the name of two files. The code below works as long as the files are on the class path.
public class cmdLineArguments {
public static void main(String[] args) {
String xmlFile1 = args[0];
String xmlFile2 = args[1];
System.out.println ("\nXmlFile1: " + args[0] + "\nXmlFile2: " + args[1]);
}
}
I would like to be able to read files that are not on the class path as well by entering their full path along with their names.
In other words, It works if I type:
C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs file1.xml file2.xml
but not if I type:
C:\Documents and Settings\user\workspace\CmdLineArgs\src>java cmdLineArgs c:\Documents and Settings\user\desktop\file1.xml c:\Documents and Settings\user\desktop\file2.xml
Would anyone please explain how I can edit the code to make it work? I guess I could take them both as a String, modify them manually (add a \ to it etc) but is there an easier way to do it? Even a reference to a tutorial, article etc about this would be very much appreciated.
Also, any idea why a code would compile and run fine in Eclipse but would create an error from command line?
Thanks a lot.