Java:我的发行版与IDE调试不同

时间:2012-08-18 02:05:29

标签: java utf-8 localization ide

当我从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

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

1 个答案:

答案 0 :(得分:0)

尝试将编码配置添加到vm:

java -Dfile.encoding=utf-8 your_main_class

通常java程序有很小的脚本启动它们(在Windows上.bat或在* n?x上的shell脚本),这样就可以把选项放到java了。