我从存储中选择了一个文本文件并获取了它的路径(FilePath
),我试图读取该文本文件的内容并将其放入edittext ..我使用下面的代码获取文本文件数据,并把它的EditText(eTPronounce)选择文本文件并阅读Android
File sdcard = Environment.getExternalStorageDirectory();
//Get the text filea
File file = new File(sdcard,FilePath);
//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');
}
br.close();
}
catch (IOException e) {
//You'll need to add proper error handling here
}
//Find the view by its i
//Set the text
eTPronounce.setText(text);
}
});
如果我和那里是文本文件,其works.For例如,如果我有“下载/文本替换filepath任何目录替换filepath(在第二行)。 TXT“它的工作原理。 我以前this链接来获取文件路径
THANKS
全码http://jpst.it/D5an –
你添加使用许可权 –
如果读比什么是问题,我想你应该检查文件是否存在该文件第一不是试图阅读它 –