2
하드 디스크에서 파일을 읽고 쓸 수있는 Firefox 추가 기능을 개발할 수 있습니까? 어떤 코드를 사용해야합니까?firefox addon을 사용하여 하드 디스크에서 파일을 읽거나 쓰는 방법?
하드 디스크에서 파일을 읽고 쓸 수있는 Firefox 추가 기능을 개발할 수 있습니까? 어떤 코드를 사용해야합니까?firefox addon을 사용하여 하드 디스크에서 파일을 읽거나 쓰는 방법?
이 링크를 제공 @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
완벽하게 감사합니다. http : //mxr.mozilla .org/mozilla-central/source/nsprpub/pr/include/prio.h # 569 – xtrm
http://stackoverflow.com/questions/4824017/browser-file-writer-extension/4825034# 4825034 – ephemient
또한 : http://simon-jung.blogspot.com/2007/10/firefox-extension-file-io.html –