I have to write a series of characters in the disk file and I want to use bulk writing to reduce disk I/O. Currently, I am using File Writer class. However, it is too slow. Can anybody help me how to perform bulk write in Java like maintaining a large buffer and periodically flush it.
You're probably interested in a FileChannel. Channels were designed to perform bulk IO operations to and from Buffers.
Ex:
FileChannel fileOut = new FileOutputStream(file).getChannel();
fileOut.write(ByteBuffer.wrap("Whatever you want to write".getBytes()));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With