Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用firefox插件从硬盘读/写文件?_Javascript_Firefox Addon - Fatal编程技术网

Javascript 如何使用firefox插件从硬盘读/写文件?

Javascript 如何使用firefox插件从硬盘读/写文件?,javascript,firefox-addon,Javascript,Firefox Addon,有没有可能开发一个Firefox插件,可以从硬盘读/写文件?我应该使用什么代码?这只是@Hypnos和@ephemient链接中代码的复制(和组合): const {Cc,Ci} = require("chrome"); //create proper path for file var theFile = 'd:\\q.txt'; //create component for file writing var file = Cc["@mozilla.org/file/local;1"].cr

有没有可能开发一个Firefox插件,可以从硬盘读/写文件?我应该使用什么代码?

这只是@Hypnos和@ephemient链接中代码的复制(和组合):

const {Cc,Ci} = require("chrome");

//create proper path for file
var theFile = 'd:\\q.txt';
//create component for file writing
var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
file.initWithPath( theFile );
if(file.exists() == false) //check to see if file exists
{
    file.create( Ci.nsIFile.NORMAL_FILE_TYPE, 420);
}
var foStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
// use 0x02 | 0x10 to open file for appending.
//foStream.init(file, 0x02 | 0x10, 0666, 0);
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0); 

// if you are sure there will never ever be any non-ascii text in data you can
// also call foStream.write(data, data.length) directly
var converter = Cc["@mozilla.org/intl/converter-output-stream;1"].createInstance(Ci.nsIConverterOutputStream);
converter.init(foStream,"UTF-8", 0, 0);
converter.writeString('Hi, This is Death. Who are you?');
converter.close(); // this closes foStream

另外:非常好用,非常感谢:)仅供参考: