简体   繁体   English

W3C / PhoneGap FileReader - 如何使用?

[英]W3C/PhoneGap FileReader - how to use?

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. 我正在使用PhoneGap(它实现了W3C FileReader的文件访问),并且有大量的在线教程,但它们似乎都导致了死胡同。 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)? 我可以使用while(!feof)的东西吗? How can I actually access what it has just read? 我怎样才能真正访问它刚才读到的内容?

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. 因此,如果在完全读取文件后将FileEntry对象传入readAsText,则会调用您提供的onloadend函数。 The property evt.target.result will contain the full text of the file you wished to read. 属性evt.target.result将包含您希望阅读的文件的全文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM