gpt4 book ai didi

java - 在 Windows 上写入 aux 文件时会发生什么?

转载 作者:可可西里 更新时间:2023-11-01 09:58:02 24 4
gpt4 key购买 nike

我有以下代码:

public class MyTest {
public static void main(String [] args) throws Exception {
java.io.File f = new java.io.File("aux.txt");
f.createNewFile();
java.io.FileWriter fw = new java.io.FileWriter(f);
fw.write("Hello");
fw.flush();
fw.close();
}
}

代码运行并且没有抛出任何异常。除了:文件 aux.txt 不存在。我发现 f.createNewFile() 返回 false,because the aux file is not allowed to be created on windows .好的,我可以接受。

但是,我的困惑是:如果 FileWriter 没有抛出任何异常,它写入了哪里?

最佳答案

根据 MSDN

Do not use the following reserved names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended.

false 返回表示文件已经存在。根据this blogWindows 上写入 AUX 会导致写入辅助设备,通常是串行端口。

此外,尝试写入名为 CON 的文件。它应该出现在控制台中。

关于java - 在 Windows 上写入 aux 文件时会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38457621/

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