package p4.io.filereader.copy;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.xml.internal.security.algorithms.implementations.IntegrityHmac;
//需求读取一个文本文件,将读取到的字符打印到控制台
//一次读取多个 这个循环次数少 更好
public class FileReaderDemo2 {
public static void main(String[] args) throws IOException {
FileReader fr=new FileReader("demo.txt");
/*
* 使用read(char[])读取文本文件数据
*
* 先创建字符数据
*/
char [] buf=new char[1024];//1024的整数倍
int len=0;
while((len=fr.read(buf))!=-1){
System.out.println(len+":"+new String(buf,0,len));
}
/* int num=fr.read(buf);//将读到的字符存储到数组中
System.out.println(num+":"+new String(buf));
int num1=fr.read(buf);//将读到的字符存储到数组中
System.out.println(num1+":"+new String(buf));
*/
fr.close();
}
}