如何使用Firefox扩展在本地文件系统中创建.txt

Shr*_*rma 6 firefox-addon

我目前正在研究ffsniff扩展代码.我必须将包含密码信息的数据保存到本地系统的文件中.我编写了我的代码,但它甚至没有在我的本地系统中创建文件.(在mozilla firefox中工作)

这是我的代码,请帮帮我.

//// here data variable contains all the information
var fso = new ActiveXObject("Scripting.FileSystemObject");
varFileObject = fso.OpenTextFile("C:\\logs.txt", 2, true,0);
varFileObject.write(data);
varFileObject.close();
Run Code Online (Sandbox Code Playgroud)

在此之后我尝试了不同的代码:

Components.utils.import("resource://gre/modules/NetUtil.jsm");
Components.utils.import("resource://gre/modules/FileUtils.jsm");

var file = Components.classes["@mozilla.org/file/directory_service;1"].
           getService(Components.interfaces.nsIProperties).
           get("Desk", Components.interfaces.nsIFile);
 file.append("logs.txt");


var ostream = FileUtils.openSafeFileOutputStream(file)

var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
            createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
var istream = converter.convertToInputStream(data);

  }
});
Run Code Online (Sandbox Code Playgroud)

但他们都没有工作..

Shr*_*rma 1

此解决方案用于在 ubuntu 中制作文件,希望这对其他人有帮助:

var file = Components.classes["@mozilla.org/file/directory_service;1"].  
               getService(Components.interfaces.nsIProperties).  
               get("ProfD", Components.interfaces.nsIFile);  
file.append("trick_new");  
if( !file.exists() || !file.isDirectory() ) {  // if it doesn't exist, create  
    file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777);  
}  
this.log_file = file.path + "/newlog.html";
Run Code Online (Sandbox Code Playgroud)