How can I make a copy of a BufferedReader?

后端 未结 3 2125
醉话见心
醉话见心 2020-12-03 11:27

I am using a BufferedReader constructor to make a new copy of an existing BufferedReader.

BufferedReader buffReader = new BufferedR         


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 12:16

    Passing in a BufferedReader instance in the constructor for a new BufferedReader will not make a copy of the original BufferedReader!

    What you are doing there is chaining the two reader, in other words, you are buffering the already buffered reader instance. When you call readLine() on buffReader, it will call readLine() on originalBuffReader.

    Take a look here for more details of the chaining of streams: Chaining of Streams

提交回复
热议问题