简体   繁体   English

将文件读入javascript数组

[英]Reading a file into a javascript array

I'm aware JS isn't a server side script, but I'm building a mobile app, and I'm going to use the web view controller on android and would like the ability to be able to read a file into an array using JS. 我知道JS不是服务器端脚本,但是我正在构建移动应用程序,并且我将在android上使用Web视图控制器,并且希望能够将文件读入数组使用JS。 Is there anyway of doing this? 反正有这样做吗?

Thanks 谢谢

You can use the HTML5 FileReader API . 您可以使用HTML5 FileReader API With it you can read the file as: 有了它,您可以将文件读取为:

void readAsArrayBuffer(in Blob blob); //Requires Gecko 7.0
void readAsBinaryString(in Blob blob);
void readAsDataURL(in Blob file);
void readAsText(in Blob blob, [optional] in DOMString encoding);

Here are few examples . 这里有几个例子

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

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