我为什么要来?当我尝试从java中的文本文件中读取ä字符时? [英] Why am i getting ?? when i try to read ä character from a text file in java?
问题描述
我正在尝试从文本文件中读取文本。有一些特殊字符,如å,ä和ö。当我创建一个字符串并打印出该字符串然后我得到??从这些特殊人物。我使用以下代码:
I am trying to read text from a text file. There are some special characters like å,ä and ö. When i make a string and print out that string then i get ?? from these special characters. I am using the following code:
File fileDir = new File("files/myfile.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(
new FileInputStream(fileDir), "UTF8"));
String strLine;
while ((strLine = br.readLine()) != null) {
System.out.println("strLine: "+strLine);
}
任何人都可以告诉我这是什么问题。我希望strLine显示并保存å,ä和ö,因为它们在文本文件中。在此先感谢。
Can anybody tell me whats the problem. I want strLine to show and save å, ä and ö as they are in text file. Thanks in advance.
推荐答案
问题可能不在于文件,而在于您尝试打印的控制台。我建议您按照以下步骤操作
The problem might not be with the file but with the console where you are trying to print. I suggest you follow the following steps
- 确保您正在阅读的文件采用UTF-8编码。
- 确保要打印的控制台具有正确的编码/字符集以显示这些字符
最后,本文< a href =http://balusc.blogspot.com/2009/05/unicode-how-to-get-characters-right.html =nofollow> Unicode - 如何让角色正确?是必读的。
这篇关于我为什么要来?当我尝试从java中的文本文件中读取ä字符时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!