0
ファイルのログに新しい行が追加されている場合は、行末を読み込むためにApacheのテイラーを使用します。プログラムは行末を表示します。これはLinuxの "tail -f"のようなものです。 。出力コンソールの末尾を取得し、文字列Javaに保存しますか?
出力テールを取得し、下のコードの文字列に保存できますか?
public class LogTailTest {
/**
* TailerListener implementation.
*/
static public class ShowLinesListener extends TailerListenerAdapter {
@Override
public void handle(String line) {
System.out.println(line);
}
}
public static void main(String args[]) {
TailerListener listener = new ShowLinesListener();
File file = new File("/home/ubuntu/Desktop/test.log");
Tailer tailer = new Tailer(file, listener, 10000, true, true);
tailer.run();
try {
Thread.sleep(1000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
tailer.stop();
}
}
私はプログラム上で実行すると、それはあなたが新しい行があなたのプログラムでを尾行されるたびに何をすべきかを定義する出力コンソール