java读大文件最快性能【转】

时间:2022-01-18 04:06:34

java读大文件最快性能

完全引用自: 几种读大文件方法的效率对比测试

据说1.88g只要5秒左右,未亲测.

/**
* 读大文件
* BufferedReader + char[]
* @throws IOException
*/
public static void readFile1() throws IOException{ long start = System.currentTimeMillis();
BufferedReader br = new BufferedReader(new FileReader(filePathName)); char[] buff = new char[];
int len = -;
while( (len = br.read(buff)) != - ){
//System.out.print(new String(buff, 0, len));
}
long end = System.currentTimeMillis();
System.out.println("读大文件 BufferedReader + char[], 耗时="+(end-start));
}