L
Lars Willich
I pass a filename to a java program through the command line. E.g.
java myprogram myfile.dat
myfile.dat is in the same directory as myprogram. Hence myprogram has no difficulties to
find the file.
When I now want to find out the path of the file then the following does NOT work:
File myFile = null;
String myfilename = args[0]; // contains "myfile.dat"
myFile = new File(myfilename);
String filepath = myFile.getParent();
System.out.println("Path=" + filepath);
yields "null"
So how do I get the path otherwise ?
Alternatively: How do a program gets his own path (only path - not filename)?
Lars
java myprogram myfile.dat
myfile.dat is in the same directory as myprogram. Hence myprogram has no difficulties to
find the file.
When I now want to find out the path of the file then the following does NOT work:
File myFile = null;
String myfilename = args[0]; // contains "myfile.dat"
myFile = new File(myfilename);
String filepath = myFile.getParent();
System.out.println("Path=" + filepath);
yields "null"
So how do I get the path otherwise ?
Alternatively: How do a program gets his own path (only path - not filename)?
Lars