Samir Junaid
Samir Junaid

Reputation: 113

Read text file with Javascript?

I'm working on mobile app through XDK intel, How can I read text file from outside the app?

I tried this code, but it's not working!

function readFile (filepath){
var txtFile = "C:\test.txt";
var file = new File(txtFile);
file.open("r"); // open file with read access
var str = "";
while (!file.eof) {
	// read each line of text
	str += file.readln() + "\n";
}
file.close();
alert(str);
     }

Upvotes: 0

Views: 1206

Answers (1)

xmnboy
xmnboy

Reputation: 2310

You are building a Cordova app (aka PhoneGap app) when you are creating an app for the Intel XDK. So the rules (and solutions) that apply to Cordova also apply to Intel XDK apps. The XDK is simply providing a way to make it easier to apply and use the standard Cordova tools, it is not providing a different runtime environment (other than including the option to replace the Android webview with a Crosswalk webview).

This describes, at a very high level, what Cordova and Cordova plugins do on an Android device > http://developer.android.com/guide/webapps/webview.html. Similar approaches are taken on iOS and Windows and other platforms supported by Cordova.

As Nicolas stated in his answer, you should use the Cordova File Plugin. On the doc page for that plugin you'll find two references that are worth reading:

Also, these may be of value:

Upvotes: 0

Related Questions