title: Reading local files from file path in javascript
body: <p>I have been struggling with reading local files <strong>from the file path</strong> in <code>javascript</code>. I have tried <code>XMLHttpRequest</code> to no avail.</p>
  
  <pre><code>function readFile(file) {
    var rawFile = new XMLHttpRequest();
    rawFile.open("GET", file, false);
    rawFile.onreadystatechange = function() {
      if (rawFile.readyState === 4) {
        if (rawFile.status === 200 || rawFile.status == 0) {
          var text = rawFile.responseText;
          document.write(text);
        }
      }
    }
    rawFile.send(null);
  }
  
  window.onload = function() {
    readFile("text.txt");
  }
  </code></pre>
  
  <p>I have also tried <code>FileReader</code> but the way I understand it is that it doesn't read files from a string file path; or how can I create a <code>File</code> object to use in <code>FileReader</code>. I also don't want to use <code>node fs module</code>. Could anyone help out on the best and surest way to read local files <strong>from the file path</strong>? THANKS</p>