我正在使用Mozilla的addon sdk進行開發,並且需要在本地系統上創建一個文件。
目前我使用下面的聲明,但覺得它可能不包括所有平臺。
在Windows 7和Windows XP上運行的語句返回:創建一個獨立於平臺的路徑字符串
console.log(system.platform);
winnt
在Linux上運行,它返回:
console.log(system.platform);
linux
是否有創建fullPath
串一個更可靠的方法,而無需檢查內容system.platform
?
pathToFile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties).get("Home", Ci.nsIFile).path;
if (system.platform.indexOf("win") == 0) {
fileSeparator = "\";
}else{
fileSeparator = "/";
}
fullPath=pathToFile + fileSeparator + 'myFile.txt'