【发布时间】:2016-02-09 16:48:51
【问题描述】:
我的 sdcard 上有一个带有 utf-8 标记的 .txt 文件,例如:
“Jak przetrwać wśród czarnych dziur”
这就是我尝试从这个文件中读取它们的方式:
public static void readBooksFromTxtFile(Context context, String filePath, ArrayList<SingleBook> books) {
BufferedReader in;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
String line = null;
while ((line = in.readLine()) != null) {
String title = line;
String author = in.readLine();
String pages = in.readLine();
String date = in.readLine();
// just for debugging
System.out.println(title);
books.add(new SingleBook(title, author, pages, date));
}
} catch (Exception e) {
Toast.makeText(context, "Error during reading file.", Toast.LENGTH_LONG).show();
return;
}
}
但它没有正确读取文件:
我做错了什么?
【问题讨论】:
标签: android utf-8 textview inputstream bufferedreader