Buffered and Unbuffered Streams in Java

前端 未结 1 664
夕颜
夕颜 2021-01-11 17:13

I was going through some of the documentation on Java IO and just wanted to make sure whether I get this right:

Unbuffered Input Streams: FileInputS

相关标签:
1条回答
  • 2021-01-11 17:30

    Rules of thumb:

    1. Any InputStream / Reader that reads directly from an external source (FileInputStream, SocketInputStream, etc.) is 'raw' and considered unbuffered. (Though in reality, there is probably some buffering going on, depends on the implementation)

    2. Any 'raw' InputStream or Reader can be buffered by a BufferedInputStream or BufferedReader.

    3. Same assumptions for OuputStreams / Writers.

    4. Other stream decorators (i.e. GZIPInputStream, MD5InputStream, YourSpecialObjectWriter) probably do some buffering, but its not very harmful to buffer the source.

    0 讨论(0)
提交回复
热议问题