Javascript 使用Cordova文件插件读取文件
我正在使用cordova文件插件- 我实际上是在从文本文件中读取文件。下面是我的代码Javascript 使用Cordova文件插件读取文件,javascript,android,cordova,filereader,phonegap,Javascript,Android,Cordova,Filereader,Phonegap,我正在使用cordova文件插件- 我实际上是在从文本文件中读取文件。下面是我的代码 document.addEventListener("deviceready", function () { window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "sameple.txt", gotFile, fail); }, true); function gotFile(file) {
document.addEventListener("deviceready", function () {
window.resolveLocalFileSystemURL(cordova.file.applicationDirectory + "sameple.txt", gotFile, fail);
}, true);
function gotFile(file) {
file.file(function (file) {
var reader = new FileReader();
reader.onloadend = function (evt) {
console.log(this.result);
}
reader.readAsText(file);
}, fail());
}
function fail(e) {
console.info("FileSystem Error : " + e);
}
因此,每当我运行这段代码时,我都会得到以下错误
deviceready has not fired after 5 seconds.
Channel not fired: onPluginsReady
Channel not fired: onCordovaReady
Could not get Cordova FileSystem: Error: deviceready has not fired after 5 seconds.
"Could not get Cordova FileSystem:"
{
[functions]: ,
__proto__: { },
description: "deviceready has not fired after 5 seconds.",
message: "deviceready has not fired after 5 seconds.",
name: "Error"
}
{"data":"data"}
在
devicerady error
之后,我能够获得准确的数据。。如何解决此错误?我是否必须等待设备就绪执行完成?发生这种情况的原因有很多,请参阅更多详细信息
您应该尝试在大多数情况下都有效的冷杉:
这非常奇怪,但它与平台文件夹中的一个错误的android.json和ios.json有关。您的源文件中包含cordova.js文件了吗?有更新吗?