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