Write to a textfile using Javascript
<p>Under Firefox, I want to do something like this  :</p>

<p>I have a .htm file, that has a button on it. This button, when I click it, the action will write a text inside a local .txt file. By the way, my .htm file is run locally too.</p>

<p>I have tried multiple times using this code, but still cant make my .htm file write to my textfile:</p>

<pre><code>function save() {
try {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
    alert("Permission to save file was denied.");
}
var file = Components.classes["@mozilla.org/file/local;1"]
    .createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( savefile );
if ( file.exists() == false ) {
    alert( "Creating file... " );
    file.create( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 420 );
}
var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"]
    .createInstance( Components.interfaces.nsIFileOutputStream );

outputStream.init( file, 0x04 | 0x08 | 0x20, 420, 0 );
var output = 'test test test test';
var result = outputStream.write( output, output.length );
outputStream.close();
</code></pre>

<p>}</p>

<p>This part is for the button:</p>

<pre><code>&lt;input type="button" value="write to file2" onClick="save();"&gt;
</code></pre>
