0
我正在使用java中的簡單腳本來監視日誌文件。 如何在腳本再次運行時檢查文件是否已更改。 應檢查發生的腳本是那句「無法」 我的腳本運行每5分鐘(Windows計劃)如何在日誌文件中添加新行時檢查 - Java
我的代碼:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class LogAgent {
public static void main(String[] args)
{
double count = 0,countBuffer=0,countLine=0;
String lineNumber = "";
String filePath = "/Users/Radek/log.txt";
BufferedReader br;
String inputSearch = "Unable";
String line = "";
try {
br = new BufferedReader(new FileReader(filePath));
try {
while((line = br.readLine()) != null)
{
countLine++;
//System.out.println(line);
String[] words = line.split(" ");
for (String word : words) {
if (word.equals(inputSearch)) {
count++;
countBuffer++;
}
}
if(countBuffer > 0)
{
countBuffer = 0;
lineNumber += countLine + ",";
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if (count == 0)
{
System.out.println("Stan poprawny");
}
else
{
System.out.println("Liczba wystapien alertu--"+count);
// System.out.println("Alert w liniach--"+lineNumber);
}
}
}