I am trying to stream lines from a file using Java and for that I NEED to use scanner as it allows me to provide my own Delimiter Pattern. Now, the problem is, after reading through the file (in a java thread), and the scanner is still open, I am trying to read the new lines entered in the file by another process (like Continuous stream). I can do this successfully with Buffered Reader but unfortunately, I cannot provide my delimiter to this Reader. so, I have to use Scanner but it is not reading these new lines in the file. Is there anyway I can make scanner read through (or refresh and get) these new lines? I don't want to read from the beginning again .I am showing the sample code here to explain clearly:
while (loopContinue) // Always true so this thread will be open for ever to keep reading this file for new messages
{
if(scanner.hasNext())
{
String line=scanner.next();
System.out.println(line);
}
else
{
Thread.sleep(10000);
}
}
scanner.close();
Any help you can provide is appreciated. Thanks