Я нашел решение для тех, кому интересно:
getLocalDirectory : function() {
let directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
let localDir = directoryService.get("ProfD", Ci.nsIFile);
localDir.append("FolderName");
if (!localDir.exists() || !localDir.isDirectory())
localDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0774);
return localDir;
},
writeFile: function(data) {
let myFile = lbbs.files.getLocalDirectory();
myFile.append("FileName.txt");
if ( myFile.exists() == false )
myFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0774);
Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");
var ostream = FileUtils.openSafeFileOutputStream(myFile)
var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var istream = converter.convertToInputStream(data);
NetUtil.asyncCopy(istream, ostream, function(status) {
if (!Components.isSuccessCode(status))
return;
});
},
readFile: function() {
let myFile = lbbs.files.getLocalDirectory();
myFile.append("FileName.txt");
if (myFile.exists() == false)
myFile.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0774);
var data = "";
var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);
var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].createInstance(Components.interfaces.nsIConverterInputStream);
fstream.init(myFile, -1, 0, 0);
cstream.init(fstream, "UTF-8", 0, 0);
let (str = {}) {
let read = 0;
do {
read = cstream.readString(0xffffffff, str);
data += str.value;
} while (read != 0);
}
cstream.close();
return data;
},
Файл теперь создается в:% USER_PROFILE% \ AppData \ Roaming \ Mozilla \ FireFox \ Profiles \ aamu4bzq.default \ FolderName \ FileName.txt