Java BufferedReader back to the top of a text file?

前端 未结 5 1101
栀梦
栀梦 2020-11-30 09:47

I currently have 2 BufferedReaders initialized on the same text file. When I\'m done reading the text file with the first BufferedReader, I use the

5条回答
  •  粉色の甜心
    2020-11-30 10:08

    What's the disadvantage of just creating a new BufferedReader to read from the top? I'd expect the operating system to cache the file if it's small enough.

    If you're concerned about performance, have you proved it to be a bottleneck? I'd just do the simplest thing and not worry about it until you have a specific reason to. I mean, you could just read the whole thing into memory and then do the two passes on the result, but again that's going to be more complicated than just reading from the start again with a new reader.

提交回复
热议问题