1

我将一个文件保存在包含一些数据的目录中,但现在需要在电话间隙中读取该文件。我尝试了这个,但我无法读取文件。这是我的保存文件和读取文件代码?我没有得到任何读取数据?我也学习 phonegap 文档但无法阅读

function saveDataOnTextFile(){
 try {
           window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
               function(fileSystem) {
                   fileSystem.root.getDirectory(CASENAME, { create: true, exclusive: false }, function(directoryEntry) {
                       console.log("log folder is created");
                       directoryEntry.getFile(DOCUMENT_NAME+".rtf", { create: true, exclusive: false }, function(fileEntry) {
                           fileEntry.createWriter(function(writer) {
                               writer.seek(writer.length);

                               writer.write($('#realTimeContents').text());
                           }, fail);
                       }, fail);
                   }, fail);
               },
               fail);
       }
       catch(e) {
           fail(e+"fail");
       }

}

function readRtfFile(){


 try {
           window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
               function(fileSystem) {
                   fileSystem.root.getDirectory(CASENAME, { create: true, exclusive: false }, function(directoryEntry) {
                       console.log("log folder is created");
                       directoryEntry.getFile(DOCUMENT_NAME+".rtf", { create: true, exclusive: false }, function(fileEntry) {
                           fileEntry.createReader(function(reader) {
                               reader.readEntries(function(entries){
                                var i;
                               for (i=0; i<entries.length; i++) {
                                console.log(entries[i].name);
                                }

                               },fail);


                           }, fail);
                       }, fail);
                   }, fail);
               },
               fail);
       }
       catch(e) {
           fail(e+"fail");
       }




}
4

0 回答 0