Reputation: 14296
I am working with PhoneGap (which implements a W3C FileReader for its file access), and there are a ton of tutorials online, but they all seem to lead to a dead end. Basically, they show you how to set everything up, but in the end, they all get to a place where it says:
myReader.readAsText(file);
What I am confused about is...what exactly does that do? Does it return some sort of index array? Can I use something along the lines of while(!feof)? How can I actually access what it has just read?
Upvotes: 3
Views: 2119
Reputation: 23273
Here is a bit more of an example:
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsText(file);
So if you pass in a FileEntry object to readAsText once the file is completely read the onloadend function, that you provide, will be called. The property evt.target.result will contain the full text of the file you wished to read.
Upvotes: 4