Fast reading of io stream text documents

package com.ute.action;


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


/**
 * 
 * @author Administrator
 * Fast reading of text documents
 */
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(){
//Get the stream object by reflection
File file1 = new File(action.class.getResource("utest.txt").getFile());
System.out.println("Test whether the file exists:"+file1.exists());//true
FileReader fr = null;
try {
fr= new FileReader(file1);
//Modify the number of reads each time, generally in binary 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 {
//Close the read stream
fr.close();
} catch (IOException e) {
e.printStackTrace ();
}
}

}

}

Guess you like

Origin blog.csdn.net/feng8403000/article/details/78213152