Why is the default char buffer size of BufferedReader 8192?

前端 未结 4 1730
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 07:52

When I construct a new BufferedReader it is providing me a buffer of 8192 characters. What is the logic/reason behind this?

8192 = 2 to the powe         


        
4条回答
  •  Happy的楠姐
    2020-12-10 08:20

    8192, as you said, is 2^13. The exact reason for this number being the default is hard to come by, but I'd venture to say it's based on the combination of normal use scenarios and data efficiency. You can specify a buffer size of whatever you want, though, using a different object constructor.

    BufferedReader(Reader in, int sz)
    

    Creates a buffering character-input stream that uses an input buffer of the specified size.

    https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html and BufferedReader default buffer size? will provide further insight.

提交回复
热议问题