gpt4 book ai didi

java - IOException - 详细消息所有问号

转载 作者:行者123 更新时间:2023-12-02 11:22:52 30 4
gpt4 key购买 nike

我要createNewFile有一条路径,但我得到了一个 IOException。问题是,详细的消息无法解释,我只能看到一堆问号。
enter image description here
我最初使用的是西类牙语的 Windows 10,但安装了中文语言包。 java语言已经设置为en和文件编码 UTF-8 :

java -version
Picked up _JAVA_OPTIONS: -Duser.country=US -Duser.language=en -Dfile.encoding=UTF-8
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
为什么?只有这个异常无法读取。
编辑:试图将语言定义为 zh ,但不起作用。
使用这个主类来重现它:
public class PromotionTargetFileHandlerMain {
public static final String uploadingDir = String.join(File.separator,
System.getProperty("user.dir"), "targets_csv");
private static final File destDir = new File(uploadingDir);

public static void main(String[] args) {
createFileDestination("target.csv");
}

public static void createFileDestination(String filename) {
if (!destDir.exists()) {
try {
Files.createDirectory(Path.of(uploadingDir));
} catch (FileAlreadyExistsException e) {
log.trace("File dir already exists: {}", uploadingDir);
} catch (IOException e) {
log.error("Cannot create temp file dir {}", uploadingDir, e);
throw new RuntimeException(e);
}
}
String saveLocation = String.join(File.separator,
uploadingDir, filename
);
File saveFile = new File(saveLocation);
if (saveFile.exists()) saveFile.delete();
try {
saveFile.createNewFile(); // <--------------- here IOException
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

最佳答案

我可能找到了一种解决方案:在 Windows 10 中为控制面板中的非 Unicode 应用程序更改区域设置。原来是西类牙语,现在改成中文了,然后就可以看到其他IO错误的一些本地化消息(无法重现问题中的相同错误):
enter image description here
我找到了 this :

...and .NET exception messages will be localized regardless of the intended recipient of the message.


所以它让我相信这个过程是这样的:
  • native 操作系统级别的错误消息始终为中文
  • 并且,由于非 Unicode 的操作系统区域设置(为什么 Java 被认为是非 Unicode 应用程序,我不知道),它想将其解释为西类牙语,但失败
  • 所以我只能看到??????

  • 在 Windows 10 中,您可以在搜索栏中输入“控制面板”,然后转到:区域 -> 管理(选项卡)-> 非 Unicode 应用程序语言,设置为中文(或其他与您本地语言包相同的语言),然后重新开始。

    当然,它也会影响其他非 Unicode 应用程序。

    关于java - IOException - 详细消息所有问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63632482/

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