Java——字符串的split方法

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);
    }
}

 

posted @ 2021-03-08 20:47  朵朵奇fa  阅读(320)  评论(0编辑  收藏  举报