2013-02-19 63 views
0

我已经创建了一个使用phonegap来定位IPad的应用程序。我使用phonegap的API动态创建了一个文本文件。文件位置显示/var/mobile/Applications/C9D4....../Documents/DataFiles。 如何访问该文件?检索IOS中的文本文件

请帮忙。在此先感谢

+0

检查该另一个问题http://stackoverflow.com/questions/10945375/phonegap-ios-how-to-get-app-documents-文件夹完整路径 – tkanzakic 2013-02-19 07:25:18

+0

感谢队友!! ..这帮助我访问iMAC中的文件。但仍然有问题在iPad中找到它。 – 2013-02-19 10:20:13

+0

你不应该尝试访问该文件的完整路径,因为它会有所不同,相反,你必须得到对'Documents'文件夹的引用,然后附加文件的名称,例如使用'[pathToDocumentsFolder stringByAppendingPathComponent:filename] ' – tkanzakic 2013-02-19 10:23:25

回答

0

试试这个

function getfile(){ 
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, onFail); 

function onFail(message) { 
     alert('Failed because: ' + message); 
    } 

    function gotFS(fileSystem) { 
     fileSystem.root.getFile("/var/mobile/Applications/C9D4....../Documents/DataFiles", {create: true}, gotFileEntry, fail); 
    } 

    function gotFileEntry(fileEntry) { 
     fileEntry.file(gotFile, fail); 
    } 

    function gotFile(file){ 
     readDataUrl(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(evt.target.error.code); 
    } 

}