title: NS_ERROR_ILLEGAL_INPUT Error while trying to read local .txt file using xul
body: <p>I am trying to read a locally stored text file in windows xp using xul program below: </p>
  
  <pre><code>function read_text_file(file_path)
  {
    var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); 
    file.initWithPath(file_path); 
    var data = "";   
    var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"].createInstance(Components.interfaces.nsIFileInputStream);   
    var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"].createInstance(Components.interfaces.nsIConverterInputStream);   
    fstream.init(file, -1, 0, 0);
    cstream.init(fstream, "UTF-8", 0, 0); // you can use another encoding here if you wish   
  
    let (str = {}) {   
    let read = 0;   
    do {
        read = cstream.readString(0xffffffff, str); // read as much as we can and put it in str.value   
        data += str.value;   
       } 
    while (read != 0);
    }
    cstream.close(); // this closes fstream
    return data;
  }
  </code></pre>
  
  <p>But getting Error in <strong>read = cstream.readString(0xffffffff, str);</strong>:</p>
  
  <pre><code>Error: NS_ERROR_ILLEGAL_INPUT: Component returned failure code: 0x8050000e (NS_ERROR_ILLEGAL_INPUT) [nsIConverterInputStream.readString]
  Source File: chrome://quicknote/content/overlay.js
  Line: 168
  </code></pre>
  
  <p><a href="https://developer.mozilla.org/en-US/docs/JavaScript_code_modules/NetUtil.jsm" rel="nofollow noreferrer">here I found</a> some description here, but it didn't help.
  <img src="https://i.stack.imgur.com/IZlCB.png" alt="enter image description here"></p>