I don't know exactly what a 'serial interface file in Linux' is. But I assume it is a simple file which has some text appended all the time and you want to wait for the new stuff appended and not read the whole file from scratch. You could use the RandomAccessFile
class' seek(long)
method to skip data. Or you could just sleep for some time when you reached the end of file.
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("src/file.txt");
int i = 0;
while (i < 50) { // read only 50 bytes
byte b = (byte)fis.read();
if (b == -1) { // end of file, wait
Thread.sleep(500L);
continue;
}
System.out.print((char) b);
i++;
}
fis.close();
}
This is just a simple example. I read only up to 50 bytes, but you want to read much more than that. Maybe you could use a timeout.