I am using the BufferedReader
String line = reader.lines().filter(stuff -> stuff.startsWith(string)).findFirst().get(); // This is called inside of another method.
BufferedReader is not reusable, as in, it can only traverse down the file, not up. When you call
.lines() that last time, you have read the entire file, and the reader will be positioned at the end of the file. You may not be expecting it to have reached the end of the file yet, but as per the docs:
After execution of the terminal stream operation there are no guarantees that the reader will be at a specific position from which to read the next character or line.
To reliably call
.lines() again, you need to instantiate the
BufferedReader again. If you want to find the next occurrence in the file, use
.skip(X).findFirst() on the subsequent calls.