我想写到我的Firefox-addon中的C:\windows\temp目录(或者它被配置为等效目录)。
https://developer.mozilla.org/en/FileGuide/FileWriting
给人的印象是,这些路径有独立于系统的名称:
var file = IO.getFile("Desktop", "myinfo.txt");
var stream = IO.newOutputStream(file, "text");
stream.writeString("This is some text");
stream.close();但是我在指定的引用中找不到任何关于“桌面”指向什么的引用。因此,这使我不知道在文档给出的名称中确切提到了什么。
如何使用IO.getFile()打开windows全局临时文件夹中的文件?
发布于 2011-01-09 13:01:36
发布于 2011-01-09 11:54:29
这些密钥被描述为这里。
我相信你想要TmpD,它是这里上市的
发布于 2016-12-14 02:42:13
// Writing stackoverflow.txt to TEMP dir
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {})
const path = OS.Path.join(OS.Constants.Path.tmpDir, "stackoverflow.txt")
OS.File.writeAtomic(path, "Hello, StackOverflow!", {
encoding: "utf-8",
tmpPath: "stackoverflow.txt.tmp", // it's not necessary but I'd recommend to use it
}).then(() => console.log(path, "has been written"))
// C:\Users\traxium\AppData\Local\Temp\stackoverflow.txt has been written
// Reading stackoverflow.txt from TEMP dir
const { OS } = Cu.import("resource://gre/modules/osfile.jsm", {})
const path = OS.Path.join(OS.Constants.Path.tmpDir, "stackoverflow.txt")
OS.File.read(path, { encoding: "utf-8" }).then(txt => console.log(txt))
// "Hello, StackOverflow!"https://stackoverflow.com/questions/4638937
复制相似问题