Reputation: 47
I want to read data from file:
FileInputStream in = openFileInput(file);
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
But I don't know "file". I want that the user tell me where the file is. I want to make him search the file with a filemanager. what should I do? I hope I explained myself and sorry for the English. Thanks in advance.
Upvotes: 1
Views: 2675
Reputation: 2263
Try this code, you can find so many examples in the web
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
}
Upvotes: 2