我有一個包含許多中文字符的txt文件,而txt文件位於res/raw/test.txt目錄中。我想閱讀文件,但不知何故,我不能讓中文字符正確顯示。這裏是我的代碼:Android:如何讀取包含中文字符的txt文件?
try {
InputStream inputstream = getResources().openRawResource(R.raw.test);
BufferedReader bReader = new BufferedReader(
new InputStreamReader(inputstream,Charset.forName("UTF-8")));
String line = null;
while ((line= bReader.readLine())!= null) {
Log.i("lolo", line);
System.out.println("here is some chinese character 這是一些中文字");
}
} catch (IOException e) {
e.printStackTrace();
}
Log.i(「lolo」,line);和System.out.println(「這裏是一些中文字符這是一些中文字」)不能正確顯示字符,我甚至不能在println()方法中看到中文字符。 我能做些什麼來解決這個問題?有誰能夠幫助我?
謝謝,我可以用你的答案解決這個問題 – TianDong 2010-06-06 12:43:01