讓您的jar文件的位置
首先創建一個文件夾(比如MyFolder文件),把你的文件裏面
考慮下面的函數
public String path()
{
URL url1 = getClass().getResource("");
String ur=url1.toString();
ur=ur.substring(9);
String truepath[]=ur.split("myjar.jar!");
truepath[0]=truepath[0]+"myfolder/";
truepath[0]=truepath[0].replaceAll("%20"," ");
return truepath[0];
}//This method will work on Windows and Linux as well.
//You can alternatively use the following line to get the path of your jar file
//classname.class.getProtectionDomain().getCodeSource().getLocation().getPath();
假設你的用戶放D:\ Test \ dist中的jar文件
然後path()將返回/ D:/ Test/dist/myfolder/
現在,你可以把「MyFolder文件」在您的jar文件駐留
這樣,您就可以訪問內部MyFolder文件
步驟分配
下載Inno Setup的編譯器文件夾內從http://www.jrsoftware.org/isdl.php運行它
選擇'使用腳本嚮導創建新的腳本文件'選項 填寫您讀應用程序的詳細信息
下一頁瀏覽您的jar文件(選擇打開對話框中的所有文件選項來查看您的jar文件)
而且五言你「MyFolder文件」添加到其他應用程序文件部分(添加文件夾)
按照其餘指示
你是一個去。
那麼,我該如何將數據保存到用戶的主目錄,或者任何在Java平臺默認的地方? – drasto 2010-04-22 09:46:33
@drasto:System.getProperty(「user.home」)將返回目錄路徑。 – 2010-04-22 10:24:20