gpt4 book ai didi

java - FileOutputStream - 有时写入数据,有时不写入

转载 作者:行者123 更新时间:2023-12-02 12:58:58 31 4
gpt4 key购买 nike

我试图理解一些java文件概念。所以我尝试使用下面的程序来理解 FileOutputStream

FileOutputStream out = new FileOutputStream("test.txt");
int i = 1;
out.write(i);
out.flush();
out.close();

一些二进制数据已写入文件中。

但是对于同一个程序,当我将 i 的值从 1 更改为 10 时。我在输出文件中看不到任何内容。有人可以用一些内部细节解释一下原因吗?

最佳答案

int i = 1;
out.write(i);

0x1 写入文件。

out.flush();
out.close();

flush() 是多余的。

Some binary data has been writen in the file.

正确。

But the for the same program when I change the value of i from 1 to 10. I don't see anything in my output file.

是的,你知道。您会看到 0xa,这是一个换行符。

关于java - FileOutputStream - 有时写入数据,有时不写入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44340966/

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