2013-02-19 65 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); 
    } 

}