我正在使用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'