title: Reading / writing file on local machine
body: <p>I pretty much copied this code right out of the <a href="https://developer.mozilla.org/en/Code_snippets/File_I%2F%2FO#Reading_from_a_file" rel="nofollow">MDN File I/O</a> page.. except I added an if statement to check if the file exists already and if it does, read it instead.</p>
  
  <pre><code>        Components.utils.import("resource://gre/modules/NetUtil.jsm");
      Components.utils.import("resource://gre/modules/FileUtils.jsm");
  
      var file = Components.classes["@mozilla.org/file/directory_service;1"].
                 getService(Components.interfaces.nsIProperties).
                 get("Desk", Components.interfaces.nsIFile);
      file.append("test.txt");
  
      if (!file.exists()) {
          this.user_id = Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001) +'-'+ Math.floor(Math.random()*10001);
  
          var ostream = FileUtils.openSafeFileOutputStream(file)
          var converter = Components.classes["@mozilla.org/intl/scriptableunicodeconverter"].
                          createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
          converter.charset = "UTF-8";
          var istream = converter.convertToInputStream(this.user_id);
  
          // The last argument (the callback) is optional.
          NetUtil.asyncCopy(istream, ostream, function(status) {
              if (!Components.isSuccessCode(status)) {
                  alert('Error '+ status);
                  return;
              }
  
              alert('File created');  
          });
      } else
      {
          NetUtil.asyncFetch(file, function(inputStream, status) {
              if (!Components.isSuccessCode(status)) {
                  alert('error '+ status);
                  return;
              }
  
              // The file data is contained within inputStream.
              // You can read it into a string with
              this.user_id = NetUtil.readInputStreamToString(inputStream, inputStream.available());
          });
          alert('File exists already, do not create');    
      }
  
      alert(this.user_id);
  </code></pre>
  
  <p>It creates the file just fine, I can open it and read it. If the file already exists however, it does not populate <code>this.user_id</code>.. just equals null. So my issue is specifically with reading the file.</p>