Inherits From:nsIOutputStream

This interface is intended to be used as an instance. To create an object implementing this interface:

var obj = Components.classes["@mozilla.org/network/file-output-stream;1"].

This interface is implemented by the following components:


void init ( nsIFile file , PRInt32 ioFlags , PRInt32 perm , PRInt32 behaviorFlags )

void init ( nsIFile file , PRInt32 ioFlags , PRInt32 perm , PRInt32 behaviorFlags )

file: - file to write to (must QI to nsILocalFile)
ioFlags: - file open flags listed in prio.h
perm: - file mode bits listed in prio.h
behaviorFlags: flags specifying various behaviors of the class (currently none supported)


This interface is passed as an argument to the following methods:

nsIURLFetcher.fireURLRequest, nsIURLFetcher.initialize

Reference documentation is generated from Mozilla's source.

Add a note User Contributed Notes
April 6, 2005, 4:47 am daniel dot kirsch at birgin dot de
The flags and modes can be found at:

Instead of just using 0x04 | 0x08 for the IO flags, I use 0x04 | 0x08 | 0x20 So the existing file content will be overwritten completely and only the new content remains. Otherwise, if your existing content has more characters than your new content, the "more" characters from your existing content will not be removed and your xml document will be non well formed.
July 16, 2004, 7:03 am jnsmith at utmb dot edu
I found that the following code works (via: peerfear)


/* Open flags
#define PR_RDONLY 0x01
#define PR_WRONLY 0x02
#define PR_RDWR 0x04
#define PR_CREATE_FILE 0x08
#define PR_APPEND 0x10
#define PR_TRUNCATE 0x20
#define PR_SYNC 0x40
#define PR_EXCL 0x80


** File modes ....
** CAVEAT: 'mode' is currently only applicable on UNIX platforms.
** The 'mode' argument may be ignored by PR_Open on other platforms.
** 00400 Read by owner.
** 00200 Write by owner.
** 00100 Execute (search if a directory) by owner.
** 00040 Read by group.
** 00020 Write by group.
** 00010 Execute by group.
** 00004 Read by others.
** 00002 Write by others
** 00001 Execute by others.


function writeFile ( str ) {
var fp =
// other filters
var res=fp.show();
if ( res == nsIFilePicker.returnOK ) {
var outputStream =
createInstance( Components.interfaces.nsIFileOutputStream );
outputStream.init( fp.file, 0x04 | 0x08, 420, 0 );
var result = outputStream.write( str, str.length );

Copyright © 1999 - 2005 XULPlanet.com