当我通过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
现在我想知道如何在不显式添加此参数的情况下更改程序
最佳答案
尝试向vm添加编码配置:
java -Dfile.encoding=utf-8 your_main_class
通常,java程序具有启动它们的微型脚本(在Windows上为
.bat
,在* n?x上为shell脚本),因此这是将选项放入Java的好地方。