Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Bulk WRITE

Tags:

java

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.

like image 740
Arpssss Avatar asked Aug 04 '26 06:08

Arpssss


1 Answers

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()));
like image 166
Jeffrey Avatar answered Aug 05 '26 20:08

Jeffrey



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!