There is a shell-script that is updating a log file.
I want to display the log from the log file while it is being written, line by line (and not the whole file at once).
Writing in the file is working properly, but I am having problems reading the file, as it displays the whole file at once.
Here is my code for reading:
String nmapstatusfile = runMT.instdir+"/logs/nmapout."+customer+".log";
String nmapcommand=runMT.instdir+"/bin/doscan.sh "+nmapoutfile+" "
+IPRange+" "+nmapstatusfile+" "+nmapdonefile;
System.out.println("nmapcommand is .. "+nmapcommand);
Runtime r = Runtime.getRuntime();
Process pr = r.exec(nmapcommand);
RandomAccessFile raf =null;
try {
System.out.println(nmapstatusfile);
System.out.println("Reading a file");
raf = new RandomAccessFile(nmapstatusfile, "r");
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} // read from input file
System.out.println("Will print file contents line by line...");
long pos = 0;
raf.seek(pos);
String line =null;
while ((line = raf.readLine())!= null) {
System.out.println("in while loop for file read.");
System.out.println(line);
}
pos = raf.getFilePointer();
pr.waitFor();
I have used RandomAccessFile, but have been unable to get the desired result.
How should I read file contents so that I can display line by line?