【发布时间】:2012-08-18 02:05:29
【问题描述】:
当我通过 NetBeans IDE 从文本文件 (UTF-8) 读取时,它可以正确读取英文和俄文字母,但是当我构建 distrib 时,运行它并读取相同的文件,它无法识别俄文字母(我猜是这样)将发生在英语以外的任何语言中)。
我错过了什么?
[https://img607.imageshack.us/img607/1558/javabug.jpg 的死链接]
更新: 我如何阅读文本文件(我排除了案例代码的所有冗余):
bReader = new BufferedReader(new FileReader(fileName));
String tempString;
tempString = bReader.readLine();
if ((tempString.length() >= 1) && (tempString.substring(0, 1).equals(""))) {
tempString = tempString.substring(1);
}
//^^^ Former excludes UTF-8 Character at the beginning of a file
//it is actually placed in "", but it can't be seen here
while (tempString != null) {
tempString = bReader.readLine();
}
所以这里没什么特别的
sir qrtt1 在下面的 cmets 中建议的实际上是有效的,即
尝试向 vm 添加编码配置:java -Dfile.encoding=utf-8 your_main_class
现在我想知道如何在不显式添加此参数的情况下更改程序
【问题讨论】:
-
请张贴代码,您究竟是如何阅读文本文件的。您似乎在某处使用了默认设置,并且它们在您的开发和运行时环境之间有所不同。
标签: java utf-8 localization ide