How to Read a Text File from the Sd Card in Android

How to read a raw text file from SD card?

This is not the complete solution, but you get the idea.

int updateVersionCode = info.versionCode;

try {
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard, "version.txt");

BufferedReader br = new BufferedReader(new FileReader(file));
String line = null;

if((line = br.readLine()) != null){
updateVersionCode = Integer.parseInt(line);
}
br.close();
}catch (Exception e) {
//Handle errors!
e.printStackTrace();
}


if (info.versionCode < updateVersionCode) {
//The local version is minor, so updates are avaliable...
}

How to read a text file from SD card in Android device through command prompt?

You don't need to pull the file.
adb provides shell acces, so you can do a cat:

adb shell cat /sdcard/D_Permission/foo.txt

If the file does not exist though, you'll still get "does not exists" error of course, which is normal.



Related Topics



Leave a reply



Submit