I'm trying to write a method for a program that only reads the last line of the text file, but I can't find out what the issue is and I have been searching for a while. Any help would be amazing.
public String getLastLine(String path) throws IOException {
String st;
String ot = null;
try {
File file = new File(path);
BufferedReader br = new BufferedReader(new FileReader(file));
while ((st = br.readLine()) != null) {
ot = st;
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
return ot;
}
Everything I have been able to find tells me to create a string and set it to null or to set it to "", but this isn't working at all for me. I keep getting this error code
org.junit.ComparisonFailure: expected:<[BZHbzAauZi]> but was:<[]>
I tried to return the last line of a text file but it only returns as a empty space.