Java BufferedReader back to the top of a text file?

前端 未结 5 1111
栀梦
栀梦 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:31

    About mark/reset:

    The mark method in BufferedReader takes a readAheadLimit parameter which limits how far you can read after a mark before reset becomes impossible. Resetting doesn't actually mean a file system seek(0), it just seeks inside the buffer. To quote the Javadoc:

    readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream may fail. A limit value larger than the size of the input buffer will cause a new buffer to be allocated whose size is no smaller than limit. Therefore large values should be used with care.

提交回复
热议问题