I am trying to create a text file, and write some text to it within my Firefox extension in this way:
try{netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");}
catch (e) {alert("Permission to write file denied."); return 0;}
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath("C:\\BrightCloud_Main\test.txt");
file.create(0x00, 0644);
var sFileContent = "This test number 1";
outputStream = Components.classes['@mozilla.org/network/file-outputstream;1']
.createInstance(Components.interfaces.nsIFileOutputStream);
outputStream.init(file,0x04|0x08|0x20,420,0);
outputStream.write(sFileContent, sFileContent.length);
outputStream.flush();
outputStream.close();
It always fires an exception, displays the message and exits. Any ideas on how to change user privileges to allow to create and edit files?!
Thanks in advance!