User Tools

Site Tools


Writing to a file

Writing to local files simply utilises the existing Mozilla XPCOM interfaces for file output streams. See the interfaces for nsILocalFile and nsIFileOutputStream for more info.

For the flags passed to foStream.init(), see prio.h

var file = Components.classes[";1"]

var foStream = Components.classes[";1"]
// 0x02 = PR_WRONLY (write only)
// 0x08 = PR_CREATE_FILE (create file if the file doesn't exist)
// 0x10 = PR_APPEND (append to file with each write)
foStream.init(file, 0x02 | 0x08 | 0x20, 0666, 0);

var data = "Hello world. This is a test string.\n";
foStream.write(data, data.length);
developer_center/recipe_book/extensions_and_core/writing_to_a_file.txt · Last modified: 2013/12/28 10:40 by geekshadow