【发布时间】:2020-02-14 20:00:53
【问题描述】:
我在 file.csv 中有这一行“ĆćĘęŁŹźł”,它被编码(如 Notepad++ 所示)为 ANSI。如何在 CcEeLzzl 等控制台中正确显示此行。
为了去除重音,我使用了来自 apache 的 StringUtils.stripAccents(myLine) 但仍然得到“��Ee����”
FileReader fr = null;
try {
String sCurrentLine;
br = new BufferedReader(new FileReader(fileName2));
while ((sCurrentLine = StringUtils.stripAccents(br.readLine())) != null) {
System.out.println(StringUtils.stripAccents(sCurrentLine));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (br != null)
br.close();
if (fr != null)
fr.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}```
I want in COnsole this "CcEeLzzl", not that "ĆćĘ꣏źł". Please help me.
【问题讨论】:
-
欢迎来到 SO!也许你会在这里找到你的答案:stackoverflow.com/questions/18141162/…
-
谢谢你,@Jonathan !!!)我试过这个。它确实将我的文件转换为 UTF-8,但我得到了这样一行 ÆæEe£�Ÿ³。
-
我怀疑字符串是正确的,不需要转换。查找curiosa的答案,您可能需要手动转换字母。
-
您应该尝试的第一件事是
br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName2), "windows-1250"));。您所说的“控制台”是指 Microsoft Windows 命令窗口吗? -
@VGR,不抱歉,“控制台”我的意思是显示 System.out.println(lineFromANSIFile)
标签: java file encoding utf-8 ansi