BufferedReader default buffer size?

前端 未结 4 1454
忘掉有多难
忘掉有多难 2021-01-02 05:27

According to the documentation, BufferedReader(Reader) uses a default buffer size, while the second constructor, BufferedReader(Reader, int) allows

4条回答
  •  执笔经年
    2021-01-02 06:00

    I'm sure I think it may be system/jvm dependent. Run this program:

    What are the default buffer size for java.io.BufferedInputStream on old and exotic JVMs?

    import java.io.BufferedInputStream;
    import java.io.InputStream;
    
    public class BufferSizeDetector extends BufferedInputStream {
        public static void main(String[] args) {
            BufferSizeDetector bsd = new BufferSizeDetector(null);
    
            System.err.println(System.getProperty("java.version"));
            System.err.println(bsd.getBufferSize());
        }
    
        public BufferSizeDetector(InputStream in) {
            super(in);
        }
    
        public int getBufferSize() {
            return super.buf.length;
        }
    }
    

    I get:

    1.6.0_45
    8192
    

提交回复
热议问题