gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 05:11:10 25 4
gpt4 key购买 nike

当我通过 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先生在下面的评论中建议的实际上有效,那就是

try add encoding configuration to vm: java -Dfile.encoding=utf-8 your_main_class

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

最佳答案

尝试向虚拟机添加编码配置:

java -Dfile.encoding=utf-8 your_main_class

通常 Java 程序都有启动它们的小脚本(Windows 上的 .bat 或 *n?x 上的 shell 脚本),因此这将是向 java 添加选项的好地方。

关于Java:我的发行版与 IDE 调试不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12015248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com