Trying to tail / parse some log files. Entries starting with a date can span many lines.
This works, but never sees new entries for the file.
File inputFile = new File("C:/test.txt"); InputStream is = new FileInputStream(inputFile); InputStream bis = new BufferedInputStream(is); //bis.skip(inputFile.length()); Scanner src = new Scanner(bis); src.useDelimiter("\n2010-05-01 "); while (true) { while(src.hasNext()){ System.out.println("[ " + src.next() + " ]"); } }
It doesn't look like the next () or hasNext () scanner is detecting new entries in the file.
Any idea how else I can implement basically -f tail with a custom separator.
ok - using Kelly we advise, I check and update the scanner, it works. Thanks!
if anyone has suggestions for improving plz do!
File inputFile = new File("C:/test.txt"); InputStream is = new FileInputStream(inputFile); InputStream bis = new BufferedInputStream(is); //bis.skip(inputFile.length()); Scanner src = new Scanner(bis); src.useDelimiter("\n2010-05-01 "); while (true) { while(src.hasNext()){ System.out.println("[ " + src.next() + " ]"); } Thread.sleep(50); if(bis.available() > 0){ src = new Scanner(bis); src.useDelimiter("\n2010-05-01 "); } }
java java.util.scanner io tail
Steve renyolds
source share