This is my code:
public int Part1(BufferedReader reader) throws IOException{
reader.mark(0);
int counter1 = 0;
String z;
while((z = reader.readLine()) != null){
counter1 = counter1 + z.length();
}
reader.reset(); // this is the error line
return counter1;
}
It is a code to count the number of characters in a file. I have other algorithm to run in the same program which requires the BufferedReader to return to the beginning of a file. I looked at another answer on StackOverFlow and was trying to use the mark() and reset() method. However, there is a run time error:
Exception in thread "main" java.io.IOException: Stream not marked at java.io.BufferedReader.reset(Unknown Source)
What is the problem here?