gpt4 book ai didi

Java 将 byte[] 写入文件 - 空文件

转载 作者:行者123 更新时间:2023-12-01 06:17:31 25 4
gpt4 key购买 nike

// Open bin file for writing:
String s = "Hello";
FileOutputStream binOutput = new FileOutputStream("out.txt");
byte[] b;
b = s.getBytes();
binOutput.write(b);
binOutput.close();

上面的代码是从 java servlet 页面运行的之后,我检查了“out.txt”,但它仍然是空的。这似乎是一项微不足道的任务。我错过了什么?

最佳答案

冲洗它:

binOutput.write(b);
binOutput.flush();
binOutput.close();

关于Java 将 byte[] 写入文件 - 空文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20534703/

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