如何使用phonegap读取目录中的保存文本文件

时间:2013-07-22 15:49:31

标签: cordova

我在目录中保存了一些文件,但是现在需要在手机间隙中读取该文件。我试试这个,但我无法读取文件。 这是我的保存文件和读取文件代码?我没有得到任何读取数据?我也研究了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");
       }




}

0 个答案:

没有答案