简体   繁体   English

如何获取Java中应用程序的安装路径?

[英]How can i get application's installation path in Java?

I pack some executable files into the installer, I want to know how can I get application's installation path(Win/Mac). 我将一些可执行文件打包到安装程序中,我想知道如何获取应用程序的安装路径(Win / Mac)。 Executable files are under the installation directory. 可执行文件位于安装目录下。

You can get User working directory (pwd in linux) using this, 您可以使用此命令获取用户工作目录(在Linux中为pwd),

String workingDirectory = System.getProperties().getProperty("user.dir"); 

You can get the .jar file location using this, 您可以使用此文件获取.jar文件的位置,

URL jarLocation = getClass().getProtectionDomain().getCodeSource().getLocation();

You can put the path into a String like so: 您可以将路径放入String中,如下所示:

String workingDirectory = System.getProperties().getProperty("user.dir");

Or print it: 或打印:

System.out.println(System.getProperties().getProperty("user.dir"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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