An exception to the BufferedReader.reset () method

I have a hasNext () method to read a file. It returns true if it is not the end of the file. In this method, it has an exception.

Exception Information:

  • Exception: java.io.BufferedReader.reset (BufferedReader.java:497)
  • Type: java.io.IOException
  • Message: Invalid

My hasNext () method:

@Override
public boolean hasNext() {
    try {
        super.getSourceRead().mark(1);
        if (super.getSourceRead().read() < 0) {
            return false;
        }
        getSourceRead().reset();
        return true;
    } catch (IOException e) {
        Logger.exceptionOccurred(e);
        return false;
    } catch (NullPointerException e) {
        Logger.exceptionOccurred(e);
        return false;
    }
}
+4
source share
1 answer

Well, as written in the doc for 1.5 :

After reading these many characters , when trying to reset the thread may fail.

So, in your case, he says that he may fail after reading 1 character.

2 .

, : , - (, :))

+2

Source: https://habr.com/ru/post/1545372/


All Articles