开发者

how to know .jar file directory [duplicate]

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜