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

时间:2018-04-16 06:28:29

标签: java windows macos path

我将一些可执行文件打包到安装程序中,我想知道如何获得应用程序的安装路径(Win / Mac)。可执行文件位于安装目录下。

2 个答案:

答案 0 :(得分:1)

你可以使用它来获取用户工作目录(在linux中使用pwd),

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

您可以使用此

获取.jar文件位置
URL jarLocation = getClass().getProtectionDomain().getCodeSource().getLocation();

答案 1 :(得分:1)

您可以将路径放入String中,如下所示:

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

或打印出来:

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