小编典典
这有点旧,但是我已经使用了该机制,并且效果很好。
诀窍是使用java.io.RandomAccessFile和,并定期检查文件长度是否大于当前文件位置。如果是,则读取数据。当您达到长度时,您将等待。洗涤,漂洗,重复。
我复制了代码,以防万一新链接停止工作
package com.javasrc.tuning.agent.logfile;
import java.io.*;
import java.util.*;
/**
* A log file tailer is designed to monitor a log file and send notifications
* when new lines are added to the log file. This class has a notification
* strategy similar to a SAX parser: implement the LogFileTailerListener interface,
* create a LogFileTailer to tail your log file, add yourself as a listener, and
* start the LogFileTailer. It is your job to interpret the results, build meaningful
* sets of data, etc. This tailer simply fires notifications containing new log file lines,
* one at a time.
*/
public class LogFileTailer extends Thr