Java---读取大文件并及时

2021-06-09 00:05

阅读:644

标签:line   class   color   文件   pre   except   reader   读取   ack   

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){
                System.out.println(line);
            }
            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\\RAW_DATA\\Data\\Site1.txt");
        loop.loopfile(file);
    }
}

 

Java---读取大文件并及时

标签:line   class   color   文件   pre   except   reader   读取   ack   

原文地址:https://www.cnblogs.com/shunguo/p/14501878.html


评论


亲,登录后才可以留言!