So im making a txt file reader, and the file has a bunch of “long” lines, because it is a prime number finder program, and it writes the numbers to the txt. when i stop the program, and then restart it, i want it to start where it left off. that means that i have to have it check each line and make sure that it is reading something, and the buffered reader is listed as long. here is the code:
try{
FileReader fileReader = new FileReader(fileLocation);
BufferedReader bufferedReader = new BufferedReader(fileReader);
long stringRead = bufferedReader.read();
while (stringRead != null)
{
stringRead = bufferedReader.read();
currentNum = stringRead;
}
bufferedReader.close();
}
catch(FileNotFoundException filenotfoundexxeption){
System.out.print("file does not exist");
}
catch(IOException ioexception){
ioexception.printStackTrace();
}
}
so the problem is that it doesn’t like the stringRead != null, and i dont know how to do it otherwise. im a noob, and so please answer using the code already listed. Thanks!
You should probably be doing
As
readLine()will return null when the end of file is reached.