【问题标题】:How can i get application's installation path in Java?如何在 Java 中获取应用程序的安装路径?
【发布时间】:2018-09-25 19:25:29
【问题描述】:

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

【问题讨论】:

    标签: java windows macos path


    【解决方案1】:

    你可以使用这个获取用户工作目录(linux中的pwd),

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

    您可以使用此获取 .jar 文件位置,

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

    【讨论】:

    【解决方案2】:

    您可以像这样将路径放入字符串中:

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

    或者打印出来:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-17
      • 2012-10-02
      • 1970-01-01
      相关资源
      最近更新 更多