上一篇讲的是如何将数据写入文件
这篇讲如何读取文件。
var storeNotification="on";//data read
var filePath = "mobovip/stores.txt";//default file path
function read(filePath) {
this.filePath = filePath;
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
};
function gotFS(fileSystem) {
fileSystem.root.getFile(filePath, {
create : true,
exclusive : false
}, gotFileEntry, fail);
}
function gotFileEntry(fileEntry) {
fileEntry.file(gotFile, fail);
}
function gotFile(file) {
//readDataUrl(file);
readAsText(file);
}
function readAsText(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
//console.log("Read as text");
// console.log("result=" + evt.target.result);
storeNotification=evt.target.result;//将读取到的数据赋值给变量
if(storeNotification==null||storeNotification.length==0){
storeNotification="on";
}
};
reader.readAsText(file);
}
function readDataUrl(file) {
var reader = new FileReader();
reader.onloadend = function(evt) {
console.log("Read as data URL");
console.log(evt.target.result);
};
reader.readAsDataURL(file);
}
function fail(evt) {
console.log("code=======" + evt.target.error.code);
}
使用很简单:
read("mobovip/notification.txt");
其中参数是需要读取文件的路径。
在readAsText(file)方法中有一个回调reader.onloadend,当读取成功后,evt.target.result就是取到的数据。
分享到:
相关推荐
这是cordova 3.4的JS主文件,用于开发Phonegap,cordova,ionic等
cordova-files-update 不更新包的情况下更新包内的文件。仅在ios上进行了测试,android平台不详。原理是把需要动态更新的文件移动到可读写的沙盒中,每次开启客户端时检查版本并利用cordova的读写文件操作完成更新。
简单的跨平台(cordova、node-webkit)文件读写API。 在cordova 下文件的根目录是cordova.file.dataDirectory ,在node-webkit 下是require('nw.gui').App.dataPath 。 cordova 实现取决于插件org.apache.cordova....
本目录的文件是以下博客所提供的文件,csdn博客(使用以下标题搜索) Android WebViews 在大型原生Android工程中嵌入一个含有cordova的WebView(制作混合应用,原生页面+H5页面)(csdn限制最低1分)
cordova-file-cache, Cordova应用的出色文件缓存 cordova-file-cacheCordova应用超出色的文件缓存基于 cordova-promise-fs 。正在启动 # fetch code using bower bower install cordova-
Cordova的文件打开器插件 该插件将使用其默认应用程序在您的设备文件系统上打开一个文件。 cordova . plugins . fileOpener2 . open ( filePath , fileMIMEType , { error : function ( ) { } , success : function ...
标题 描述 文件传输 上传和下载文件。 AppVeyor 特拉维斯CI 科尔多瓦插件文件传输 使用须知 通过和引入的新功能,您的用例可能不再需要此插件。 对于小文件传输,您可能不需要此插件。...cordova plugin add cordo
最新的cordova-js版本
Cordova+vue 项目实现图片懒加载并网络图片下载到本地实现本地加载,提高图片加载速度 如要插件 npm install --save js-md5 cordova-plugin-file cordova-plugin-file-transfer 在mian.js 中引入使用
cordova-screenshot cordova截屏插件 document.addEventListener("deviceready", init, false); function init() { document.querySelector("#share").addEventListener("touchend", function() { navigator....
NULL 博文链接:https://rensanning.iteye.com/blog/2047322
这是cordova 3.4的jar和js,用于开发Phonegap的
上传的是前端的vue界面代码加codorva支持的分块上传代码,代码是针对移动端的(安卓和ios都可以,用的cordova工具),本来想在网上搜个cordova的分块案例,结果没有,就使劲儿研究了一下,写了个分块上传的粗糙代码...
Cordova 插件,用于将 base64 数据下载为二进制文件。 安装 从github获取最新代码并安装: cordova plugin add https://github.com/openlabs/cordova-binary-file-handler 将 base64 下载为二进制文件 此插件将添加...
cordova跳转原生Activity
实实在在经过ant编译的cordova-2.9.1.jar 而不是有些人坑蒙拐骗的rar文件
If you’re familiar with an older version of Cordova, this book will show you in detail how to use all of the new stuff that’s in Cordova 3 plus stuff that has been around for a while (like the ...
Cordova简介 【http://cordova.apache.org/docs/en/latest/guide/overview/】 Cordova是一个开源的移动终端开发框架,它提供使用html,css,javascript 技术进行跨平台开发能力,并且封装了一组javascript接口实现...
Cordova FileChooser插件 需要Cordova> = 2.8.0 使用Cordova CLI安装 ...成功回调获取所选文件的uri fileChooser.open(function(uri) { alert(uri); }); 截屏 TODO重命名open以选择,选择或选择。
说明Key有问题,可以检查下生成的AndroidManifest.xml文件里面是否有如下信息 如果没有,说明插件使用不当,尝试重新安装,如果有这些信息,说明Key与当前程序AndroidManifest.xml 中的package...