0

I am currently just trying to read one file using FileReader(). Here is the code I have so far,

<script>
    var file = new File("file:///C:/path/to/file");
    var reader = new FileReader();
    var block = document.getElementById("block");
      reader.onload = function(){
      block.innerText = reader.result;
    };

    reader.readAsText(file);
</script> 

I get an error saying that I need 2 arguments instead of 1 argument when instantiating a new File. What do I need for the first argument?

Adi Prasetyo
  • 1,006
  • 1
  • 15
  • 41
user1058860
  • 513
  • 2
  • 9
  • 21
  • Possible duplicate of [How to instantiate a File object in JavaScript?](http://stackoverflow.com/questions/8390855/how-to-instantiate-a-file-object-in-javascript) – Sterling Archer Mar 09 '16 at 22:40
  • 2
    You can not achieve what you are trying to do here. There is no way to gain access to the local filesystem from browser javascript – Brennan Mar 09 '16 at 22:43
  • 1
    IMO not duplicate, @user1058860 see the [solutions](http://stackoverflow.com/a/26181292/2368696), what is your goal using FILE API? – Adi Prasetyo Mar 09 '16 at 22:45
  • But, for what it's worth, it appears the first arg to the `File` constructor should be an array, probably of binary data. You really probably shouldn't ever need to use the `File` object directly – Brennan Mar 09 '16 at 22:45
  • I am just trying to pass the first two words of the text file into variables to print to the web page – user1058860 Mar 09 '16 at 22:57

0 Answers0