// copied from http://www.mozdevgroup.com/docs/pete/jslib.html
try {
  var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
  
  // local file path for windows
  file.initWithPath("/tmp/foo");
  
  if (!file.exists())
    file.create(file.NORMAL_FILE_TYPE, 0644);
  
  var ioService = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
  var uri = ioService.newFileURI(file);
  var channel = ioService.newChannelFromURI(uri);
  var outputStream = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  
  outputStream.init(file, 0x20|0x02, 00004, null);
  var buffer = "This is a test!!\n";
  
  outputStream.write(buffer, buffer.length);
  outputStream.flush();
  outputStream.close();
} 
catch (e) { 
  dump(e); 
}
