// 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/