簡體   English   中英

如何獲取Java中應用程序的安裝路徑?

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

我將一些可執行文件打包到安裝程序中,我想知道如何獲取應用程序的安裝路徑(Win / Mac)。 可執行文件位於安裝目錄下。

您可以使用此命令獲取用戶工作目錄(在Linux中為pwd),

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

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

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

您可以將路徑放入String中,如下所示:

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

或打印:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM