简体   繁体   中英

Java write byte[] to file - empty file

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

The above code was run from a java servlet page After this, I checked "out.txt" but it remained empty. It seems like a trivial task. What am I missing?

Flush it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM