public class FileReaderTest { public static void main(String[] args) { Reader fr=null; try{ //2.实例化FileReader对象 fr =new FileReader("D:\\doc\\诗词.txt"); char[] ch= new char[1024];//创建字符数组为转储容器 int len=0;//保存实际储存字符数 //3.循环读取数据 while((len=fr.read(ch))>0){ System.out.println(new String(ch,0,len)); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { if (fr!=null){ try{ fr.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
标签:fr,ch,字节,FileReader,len,printStackTrace,new,输入 From: https://www.cnblogs.com/max-hou/p/18448229