This is the function to get a file from external storage:-
private File getFileFromSD(String fileName)
{
File sdcard = Environment.getExternalStorageDirectory();
return new File(sdcard,fileName);
}
Function implementation:-
/* For example, you have a text file(text.txt) and you want to read the content of it*/
StringBuilder fileData= new StringBuilder(); /*At the end of the execution all the text stored on the file will be pasted on the StringBuiler() that is fileData.*/
try {
BufferedReader buffer = new BufferedReader(new FileReader(getFileFromSD("text.txt")));
String data;
while ((data= buffer.readLine()) != null) {
fileData.append(data);
fileData.append('\n');
}
buffer.close();
}
catch (IOException e) {
Log.e(TAG,e.getMessage());
}