Cordova-file-plugin创建从文件读取的功能

时间:2018-03-30 21:08:49

标签: cordova

这是我的函数pnrread()中的代码,cordova文件插件用于从文件中读取。 但是当我调用pnrread()然后在警告框中它返回" undefined"。
文件pnr.txt具有数据,就像console.log(this.result)提供文件数据但警报没有给出。

alert(pnrread);
function pnrread(){
       window.resolveLocalFileSystemURL(cordova.file.externalCacheDirectory, function(fs) {
        fs.getFile("pnr.txt",{ create: false, exclusive: false }, function (fileEntry) {
            console.log("fileEntry is file?" + fileEntry.isFile.toString());
            fileEntry.file(function (file) {
            var reader = new FileReader();
            reader.onloadend = function() {
               var res=this.result;
               console.log(this.result)
                return res; 
        };
            reader.readAsText(file);
            });
        },pnrCreateFile);
    })   
    }
}

cordova-file-plugin的文档:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/

0 个答案:

没有答案