File Handling's BufferInputStream vs FileInputStream [closed]

18 hours ago 1
ARTICLE AD BOX

flow FIS : disk ->read-> My Buffer(64kb) -> write->disk

flow BIS : disk->read->internal Buffer(256kb) ->my buffer(64kb )->internal Buffer -> disk

why can't we use one single buffer of (256+64)kb why BIS use case came .. FIS's 256+64 kb buffer will also reduce disk hits same as BIS (256kb).. then why to use BIS and when to use what??

Kumar Abhinav's user avatar

New contributor

Kumar Abhinav is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

4

Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.

2026-02-06 05:12:16 +00:00

Commented 1 hour ago

The purpose of BufferedInputStream is clearly outlined in javadoc: A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. If you are not using mark/reset, simply do not use BufferedInputStream as well: perform reads and writes via single byte array or use FileChannel and ByteBuffer

2026-02-06 05:17:36 +00:00

Commented 1 hour ago

What do you mean by "internal buffer" and "my buffer" here? Is "internal buffer" the buffer managed by BufferedInputStream and "my buffer" a byte[] you're managing yourself? If yes, then when you manage your own byte[] you shouldn't use a BufferedInputStream, unless you want to utilize its mark-and-reset functionality.

2026-02-06 05:18:46 +00:00

Commented 1 hour ago

If your reads are all block-aligned there is no need to use BufferedInputStream here.

2026-02-06 06:25:52 +00:00

Commented 34 mins ago

Read Entire Article