how to know .jar file directory [duplicate]

拥有回忆 提交于 2019-12-25 08:40:29

问题


Possible Duplicates:
Where on the file system was my java class loaded from?
How do I get the directory that the currently executing jar file is in?

How can i know .jar file directory within my program i want to use this directory to create another files in same directory which user save this .jar file


回答1:


I don't think you can easily find out where the JAR file is, but you can find out which directory your program is being run from:

File cwdFile = new File (".");
String cwd = cwdFile.getAbsolutePath();

This only works if the user actually runs the JAR file from the directory it's in:

java -jar MyExectuableJar.jar

If they run it from another directory, like this:

java -jar /usr/bin/java/MyExecutableJar.jar

then you'll get whichever directory the user happens to be in at the time.



来源:https://stackoverflow.com/questions/5053150/how-to-know-jar-file-directory

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