【问题标题】:Very weird FileOutputStream behavior on WindowsWindows 上非常奇怪的 FileOutputStream 行为
【发布时间】:2016-02-18 21:23:41
【问题描述】:

我已经检查了所有可用于本地 Windows 的源代码 CreateFileWWriteFilejdk8u/jdk/src/windows/native/sun/nio/ch/FileDispatcherImpl.c 中调用,但我不知道为什么这两个调用会创建具有不同长度的文件:

FileOutputStream f = new FileOutputStream(new File("x.cfg"));
f.write("hello\n".getBytes());
f.close();

FileOutputStream f = new FileOutputStream(new File("x.txt"));
f.write("hello\n".getBytes());
f.close();

我尝试了不同的扩展,但似乎只有.cfg导致LF→CRLF转换...

看起来这不是 Java 的问题,只是 Windows 的问题。

【问题讨论】:

  • 使用 JDK1.8.0_65 这两个文件在我的系统上都有 6 个字节(Windows 7 64 位)。内容可能被病毒扫描程序更改了吗?
  • 我试过JDK1.8.0_66,Windows 2012R2
  • 您应该检查是否分配了 config.properties 文件。我不确定具体细节,但这里有一个用法链接crunchify.com/…
  • Java 问题,而不是 Windows 问题。 WriteFile 不转换任何内容,CreateFile 不提供指定 text 输出的方法。所有必需的转换都必须在 Windows API(即 CRT 或 JVM)之上实现。

标签: java windows io


【解决方案1】:

好的,问题是 OSGi 文件安装服务在文件写入之后进行了转换...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-13
    • 2011-03-01
    • 2020-12-02
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 2020-02-09
    • 1970-01-01
    相关资源
    最近更新 更多