我需要扫描日志以查找多个关键字错误、操作系统、ARCH。以下代码适用于单个关键字搜索
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ErrorScanner
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner s = new Scanner(new File("Users/home/test.txt"));
boolean ifError = false;
while(s.hasNextLine())
{
String nextLine = s.nextLine();
if(nextLine.contains("ERROR"))
{
System.out.println("Failed" + " " + nextLine);
ifError = true;
}
}
if(! ifError)
{
System.out.println("Nothing found");
}
}
}