package Demo; import java.util.*; import java.io.*; //import org.apache.*; import org.apache.commons.io.FileUtils; public class loop { public static void loopfile (File file){ try{ long start = System.currentTimeMillis(); FileReader fr = new FileReader(file); BufferedReader br = new BufferedReader(fr); String line; while (( line = br.readLine()) != null){ if (line.indexOf("Data_P",0) != -1){//如果不在里面返回的就是-1 String[] stringlist = line.split(" {1,}");//{1,}匹配一个或者多个空格 System.out.println(stringlist[stringlist.length-1]); } } br.close(); long end = System.currentTimeMillis(); long diff = (end - start)/1000; System.out.println("循环耗时: " + diff); }catch (Exception e){ e.printStackTrace(); System.out.println(e); } } public static void main(String[] args){ File file = new File("C:\work_data\Script&Tool\FT offline tool_RAW_DATA\Data\20201012050318_Site1.txt"); loop.loopfile(file); } }