简体   繁体   中英

How do I get the path where the user installed my Java application?

I want to bring up a file dialog in Java that defaults to the application installation directory.

What's the best way to get that information programmatically?

System.getProperty("user.dir") 

获取Java VM启动的目录。

System.getProperty("user.dir");

The above method gets the user's working directory when the application was launched. This is fine if the application is launched by a script or shortcut that ensures that this is the case.

However, if the app is launched from somewhere else (entirely possible if the command line is used), then the return value will be wherever the user was when they launched the app.

A more reliable method is to work out the application install directory using ClassLoaders .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM