问题
I have a Java application which I call from the command prompt like this:
C:\Mydir> C:\dir2\my.exe
When I call this application I would like to retrieve at the same time the path "C:\MyDir", i.e. the active directory from where my exe is called in the prompt and not "C:\dir2\" where the exe is found.
How could I do that in Java?
回答1:
I believe you would use
String currentLocation = System.getProperty("user.dir");
回答2:
File f = new File("");
System.out.println(f.getAbsolutePath());
来源:https://stackoverflow.com/questions/9787150/get-current-directory-from-the-command-prompt-when-calling-a-java-application