1

当我通过 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();
}

所以这里没什么特别的

qrtt1 先生在下面的评论中建议的实际上是有效的,即

尝试将编码配置添加到 vm: java -Dfile.encoding=utf-8 your_main_class

现在我想知道如何在不显式添加此参数的情况下更改程序

4

1 回答 1

0

尝试向 vm 添加编码配置:

java -Dfile.encoding=utf-8 your_main_class

Usually java programs have tiny scripts that start them (.bat on windows, or shell scripts on *n?x), so that would be a great place to put options to java.

于 2012-08-20T13:09:52.403 回答