I have some text files on my android's SD Card, and i need to access one of them. I came across the below code here:
//Find the directory for the SD Card using the API
//*Don't* hardcode "/sdcard"
File sdcard = Environment.getExternalStorageDirectory();
//Get the text file
File file = new File(sdcard,"file.txt");
//Read text from file
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');
}
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its id
TextView tv = (TextView)findViewById(R.id.text_view);
//Set the text
tv.setText(text);
But in this part of the code:
//Get the text file
File file = new File(sdcard,"file.txt");
the name of the text file is specified but i need the user to choose the text file he wants (from those text files in SD Card). So how can i let the user brows the SD Card and choose the file he wants?