有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在java apache中。平民io,如何避免读取旧的日志消息

我正在使用java Tail listener API来实现tailf函数(在Linux中)。也就是说,每当日志文件中的日志消息被更新时,这个API就会打印这些消息

我的代码如下

    public static void main(String[] args) {
        // TODO code application logic here
        File pcounter_log = new File("\vat\temp\test.log");

        try {
            TailerListener listener = new PCTailListener();
            Tailer tailer = new Tailer(pcounter_log, listener, 5000, true);

            Thread thread = new Thread(tailer);
            thread.start();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

public class PCTailListener extends TailerListenerAdapter {
    public void handle(String line) {
        System.out.println(line);
    }
}

一开始,它工作正常。一段时间后,它将读取旧的日志消息(此应用程序启动时生成的日志消息)。此外,它还可以读取新的日志消息。如何避免读取已监视的日志消息。如何做到这一点


共 (0) 个答案