Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Buffer Size for BufferedInputStream

How to determine the size of Buffer, while using Buffered Input Stream for reading batch of files? Is it based on the File size?I'm using,

byte[] buf = new byte[4096];

If i increase the buffer size,it will read quickly?

like image 414
user2507974 Avatar asked Sep 05 '26 01:09

user2507974


2 Answers

The default, which is deliberately undocumented, is 8192 bytes. Unless you have a compelling reason to change it, don't change it.

like image 55
user207421 Avatar answered Sep 07 '26 14:09

user207421


You can easily test it yourself, but it's not really a big issue. A few kilobytes is enough for the buffer, so you'll get good reading speeds.

If you profile your application and do realize that File IO is a performance bottleneck, there are ways to make it quicker, such as memorymapping a file.

like image 28
Kayaman Avatar answered Sep 07 '26 16:09

Kayaman



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!