How can you read a file in Android using PhoneGap and Javascript? I tried several snippets of code given at different sites but failed to do so. Actually I am a beginner and know very little about Phonegap. I also tried FileReader function but don't know where to put the file which will be readed by this function.
Asked
Active
Viewed 8,112 times
1 Answers
1
The FileWriter full example at http://docs.phonegap.com is designed to work with the FileReader full example. FileWriter writes readme.txt and FileReader reads it back in.

Paul Beusterien
- 27,542
- 6
- 83
- 139
-
It worked for me and reads the file when I put it on the sdcard but when I put the file in "assets\www" folder then it gives error " File3 = TypeError: Result of expression 'evt.target' [undefined] is not an object".Actually I dont know how to give the path when someone puts the file in assets\www folder.So can you please tell me that – Waseem Jan 21 '12 at 19:50
-
Use window.resolveLocalFileSystemURI. See http://stackoverflow.com/questions/8326272/access-files-from-assets-www-directory – Paul Beusterien Jan 22 '12 at 02:20
-
However, I can't get window.resolveLocalFileSystemURI to work. Another option would be to incorporate the file directly into your JavaScript as a string or array assignment since you must know the data at build time to put it in the assets bundle. – Paul Beusterien Jan 22 '12 at 17:14
-
It's not possible to use the File APIs on the www folder. See https://groups.google.com/forum/#!topic/phonegap/Sw2wThOYm8c – Paul Beusterien Jan 23 '12 at 21:44