Roedy Green said:
That is called the current directory. See
http://mindprod.com/jgloss/file.html
If you want the working directory it works fine but if you want to know
where the "main class is running" from (where MainClass.class) is at then it
won't work. I even tried it.
import java.io.*;
public class WorkingDir {
public static void main(String[] args) throws Exception {
File f = new File(".");
String path = f.getCanonicalPath();
System.out.println(path);
}
}
If I have the class file in a folder "WD/a/" and run this command from "WD/"
java -cp a WorkingDir
I get WD
Where if I run this command from "WD/a/"
java WorkingDir
I get WD/a
I found a small library somewhere once that managed to get that information.
Of course I can't find it now, but if you search the web you will find it.
In fact, it claims to get the directory where the jar file is if it is
running from a jar file.