Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReadAsText() arguments

Tags:

javascript

I'm totally new to javascript (Hello World Level), I've made a lot of searches in google but couldn't even find one result explaining what arguments the ReadAsText() method get. I've tried to put the address of a file and encoding format but I keep receiving "Type mismatch" error. I'm using it this way :

reader.readAsText ("d:\\file.txt", "UTF-8");

I know that this question is not really a match for StackOverFlow but if I found any result in google I wouldn't post it here.

By the way when I use it this way it works very well:

function FileReader (f) {
 var reader = new FileReader();
 reader.readAsText (f);
 var text = reader.result();
}

and then

<input type="file" onchange="readfile(this.files[0])"></input>

but I don't know why it shows error when I type in the address of the file statically.

like image 581
First Last Avatar asked Dec 05 '25 03:12

First Last


1 Answers

readAsText takes a Blob or File object as the first argument; any argument of a different type will cause the type error. In your working example you pass a File object which is why it works.

like image 184
Musa Avatar answered Dec 06 '25 18:12

Musa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!