我試圖將我的應用程序的數據存儲到/ Library/Application Support/myAppFolder。寫入OSX /庫/應用程序支持文件夾會拋出IOException異常:權限被拒絕
我與此代碼試圖(通過調試)
String content = "This is the content to write into file";
File file = new File("/Library/Application Support/filename.txt");
// if file doesnt exists, then create it
if (!file.exists()) {
file.mkdir();
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(content);
bw.close();
System.out.println("Done");
但產生java.io.IOException:權限被拒絕被拋出。
..謝謝很多! – user2468425
@ l'l l是的,這是我的假設,因此建議使用'System.getProperty(「user.home」)'作爲路徑的前綴 – MadProgrammer