我想从文件中读取数据:
FileInputStream in = openFileInput(file);
InputStreamReader inputStreamReader = new InputStreamReader(in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
但我不知道“档案”。我希望用户告诉我文件的位置。我想让他用文件管理器搜索文件。我该怎么办? 我希望我解释自己并抱歉英语。提前谢谢。
答案 0 :(得分:2)
试试这段代码,你可以在网上找到很多例子
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
}