문제

I've tried to read a file from the app bundle using phonegap's FileReader class:

...
loadFile: function (path, callback) {
   fileReader = new FileReader(); 

   fileReader.onerror = function () {
     ...
   }

   fileReader.onload = function (evt) {
     callback(evt.target.result);
   }

   fileReader.readAsText("./www/" + path); 
}

In this example path is something like "index.html". The onerror callback is never called. onload is called but evt.target.result is empty. Do you have any suggestions? Is it in general possible to read files from the bundle with the phonegap API? Can I use relative paths like "./www/foo.txt"?

Thanks for your answers!

도움이 되었습니까?

해결책

The path that is passed into readAsText is relative to the "Documents" folder in the applications sandbox. Hence you have to simply fix the path by replacing the line

fileReader.readAsText("./www/" + path); 

with

fileReader.readAsText("./../myApp.app/www/" + path); 

to access the file. This works for me.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top