Write File

Can anyone tell me why this code doesn’t work in Thunderbird 0.9 (I haven’t tried Firefox 1.0).

Note: There is a slash in the directory path C:, for some reason wordpress is fudging it up. MovableType did this crud too. So it’s not showing, but it’s there in the code.

function sync()
testFileOutputStream("C:\foo.txt", "la la la \n robert");
function testFileOutputStream(path, buffer) {
  // file is nsIFile, data is a string
  var stream = Components.classes[";1"]
  // use 0x02 | 0x10 to open file for appending.
  stream.init(nsLocalFile(path), 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
  stream.write(buffer, buffer.length);
function nsLocalFile(path)
    const LOCALFILE_CTRID = ";1";
    const nsILocalFile = Components.interfaces.nsILocalFile;
    var localFile =
    return localFile;

Keep getting this error:

Error: uncaught exception: [Exception… “Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIFileOutputStream.init]” nsresult: “0x80004005 (NS_ERROR_FAILURE)” location: “JS frame :: chrome://extension/content/extension.js :: testFileOutputStream :: line 12” data: no]

Simply want to be able to write to C: (or any place on my HD that I specify). Prefer not to use JSlib, simply because I don’t want dependencies. It’s really borderline insane to think you can’t do something as simple as write out to a file without depending on other lib’s.

Thanks in advance.

Comments/Email as usual.

3 replies on “Write File”

Hmm don’t really have time to look over that code, but why don’t you use MonkeySagee’s IO lib, it’s small and has everything you could need.
I know it works in TB as that is what we use for QuickNote.

If you’d rather not use it, I’m sure it will point you in the right direction on what you need to add/change.

-Jed πŸ™‚

Wild speculation: you said there was a backslash, but don’t you need to put a double-backslash? Otherwise the \ just escapes (needlessly) the : following it and never actually makes it anywhere… so it would be attempting to output to “C:foo.txt” ?

Of course you might well be doing that already, in which case ignore this comment πŸ˜‰

I have been anxiously awaiting Google’s web browser’s widgets for months it seems – At this point I have played with 5 extensions and am awed with the plugins. FF has always slowed down & the extensions are welcomed.

Leave a Reply

Your email address will not be published. Required fields are marked *