Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
6
rated 0 times [  12] [ 6]  / answers: 1 / hits: 19979  / 11 Years ago, sat, february 22, 2014, 12:00:00

Consider the following code


function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var myFile = evt.target.files[0];
var reader = new FileReader();
reader.readAsText(myFile);
var myString = reader.toString();
alert(myString); // print - "[object FileReader]"
}

I try to get all the file content into String , for example if the file content is


helloWorld1
helloWorld2

I will get alert of that's content .


More From » filereader

 Answers
11

That's not how you get the result of a FileReader. Modify your code to this:



function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var myFile = evt.target.files[0];
var reader = new FileReader();
reader.readAsText(myFile);
reader.onload=function(){alert(reader.result)}
}

[#72367] Friday, February 21, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
randall

Total Points: 492
Total Questions: 99
Total Answers: 103

Location: Solomon Islands
Member since Fri, Oct 8, 2021
3 Years ago
randall questions
Wed, Mar 16, 22, 00:00, 2 Years ago
Tue, Nov 10, 20, 00:00, 4 Years ago
Sat, Oct 31, 20, 00:00, 4 Years ago
;