how to know .jar file directory [duplicate]
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.
精彩评论