Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap Android read file on sdcard with JavaScript

I am trying to read a text file with JavaScript using Phonegap 2.0.0 on Android. I went over several examples using the File API at http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File Nothing seems to work.

I read several related threads on Stackoverflow, for example:

How to read file in android using PhoneGap Javascript

Android HTML5 FileApi can i read file from SD Card?

and How to create a new file among others. Yet none of the techniques seem to work.

I am using Nexus One with API 8. The android app loads a URL: http://www.mydomain.com/read_text_file.html which contains the JavaScript utilizing the PhoneGap framework. I am trying to access a file on the SD card located at: /sdcard/textfile.txt. I specify the path to the file in the JavaScript as: file:///sdcard/textfile.txt

For the time being my goal is to trigger an alert from the JavaScript upon page load and show the file contents ( which is just "test file" )

like image 665
Bai Avatar asked Mar 25 '26 07:03

Bai


1 Answers

In Place of "file:///sdcard/textfile.txt" try to use only "textfile.txt".

It seems to work fine.

like image 78
Soumyaranjan Nayak Avatar answered Mar 26 '26 20:03

Soumyaranjan Nayak