开发者

how to know .jar file directory [duplicate]

开发者 https://www.devze.com 2023-02-11 22:54 出处:网络
This question already has answers here: 开发者_StackOverflow Closed 11 years ago. Possible Duplicates:
This question already has answers here: 开发者_StackOverflow Closed 11 years ago.

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消