title: How to open a local file with Javascript FileReader()
body: <p>I would like to modify <a href="http://www.webdeveloper.com/forum/showthread.php?261923-how-to-use-javascript-in-html-to-read-txt-file-and-display-it&amp;p=1212291#post1212291" rel="noreferrer">this code</a> so that it works with a specific file only, but I can't figure out the correct URL parameter and all the code examples that I've found use a file selection dialog. </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;reading file&lt;/title&gt;
      &lt;script type="text/javascript"&gt;
  
          var reader = new FileReader();
  
          function readText(that){
  
              if(that.files &amp;&amp; that.files[0]){
                  var reader = new FileReader();
                  reader.onload = function (e) {  
                      var output=e.target.result;
  
                      //process text to show only lines with "@":             
                      output=output.split("\n").filter(/./.test, /\@/).join("\n");
  
                      document.getElementById('main').innerHTML= output;
                  };//end onload()
                  reader.readAsText(that.files[0]);
              }//end if html5 filelist support
          } 
  &lt;/script&gt;
  &lt;/head&gt;
    &lt;body&gt;
      &lt;input type="file" onchange='readText(this)' /&gt;
      &lt;div id="main"&gt;&lt;/div&gt;
    &lt;/body&gt;
  </code></pre>
  
  <p>Why doesn't it work when I change the code from:</p>
  
  <pre><code>&lt;body&gt;
      &lt;input type="file" onchange='readText(this)' /&gt;
      &lt;div id="main"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>to:</p>
  
  <pre><code>&lt;body onload="readText('file:///C:/test.txt')"&gt;
      &lt;div id="main"&gt;&lt;/div&gt;
  &lt;/body&gt;
  </code></pre>