io流文本文档的快速读取

package com.ute.action;


import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;


/**
 * 
 * @author Administrator
 * 文本文档的快速读取
 */
public class action {
public static void main(String[] args) {
Long start=System.currentTimeMillis();
action.teIO();

Long end=System.currentTimeMillis();

System.out.print("用时");

System.out.println(end-start);
}

public static void teIO(){
//通过反射的方式获取流对象
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("文件是否存在测试:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//修改每次读取的个数,一般为2进制递进64-128-256-512-1024
char [] c=new char[64];
while (fr.read(c) != -1) {
System.out.println(c);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
try {
//关闭读取流
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

}

猜你喜欢

转载自blog.csdn.net/feng8403000/article/details/78213152
今日推荐