Get current directory from the command prompt when calling a Java application

故事扮演 提交于 2020-04-16 08:30:09

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!