Skip to content

Instantly share code, notes, and snippets.

@littlebtc
Created December 27, 2009 09:41
Show Gist options
  • Select an option

  • Save littlebtc/264223 to your computer and use it in GitHub Desktop.

Select an option

Save littlebtc/264223 to your computer and use it in GitHub Desktop.
var writeIntoFile = function(filepath, content, charset) {
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(filepath);
var fostream = Components.classes["@mozilla.org/network/file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
fostream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);
/* Get a charset converter-enabled stream */
var costream = Components.classes["@mozilla.org/intl/converter-output-stream;1"]
.createInstance(Ci.nsIConverterOutputStream);
costream.init(fostream, charset, 0, 0x0000);
costream.writeString(content);
/* Close everything */
cosstream.close();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment