How to read a .txt file from sdcard.I tried the following method but it returns empty string saying file not found exception
public String ReadFile(){
File sdcard = Environment.getExternalStorageDirectory();
File file = new File(sdcard,"/folder/json.txt");
StringBuilder text = new StringBuilder();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
Toast.makeText(this, "No data exist", Toast.LENGTH_SHORT).show();
}
String flag=text.toString();
return flag;
}
ERROR:/storage/emulated/0/folder/json.txt: open failed: ENOENT (No such file or directory)