0
点赞
收藏
分享

微信扫一扫

io流文本文档的快速读取

进击的铁雾 2022-03-11 阅读 38
java进制

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


}


}



}



}


举报

相关推荐

0 条评论