1 package cn.itsource._inputsteam; 2 3 import java.io.FileNotFoundException; 4 import java.io.FileReader; 5 import java.io.IOException; 6 7 public class FileReadreTest { 8 9 /* 10 * 该类用于字符输入流: 11 * 就是把硬盘中储存的数据读取到内存中来 12 * 构造方法 13 * 1.FileReader(File file) 14 * 2.FileReader(String filename) 15 * filename:文件名(相对路径或者绝对路径) 16 */ 17 public static void main(String[] args) throws IOException { 18 FileReader fr = null; 19 try { 20 fr = new FileReader("E:/洛晟.txt"); 21 int read = 1; 22 char[] c = new char[10]; 23 while((read = fr.read(c, 0, c.length)) != -1){ 24 System.out.println(new String(c, 0, c.length)); 25 } 26 } catch (FileNotFoundException e) { 27 e.printStackTrace(); 28 } catch (IOException e){ 29 e.printStackTrace(); 30 } finally { 31 //关流,调用自己封装的功能,没有的流直接传null 32 IOUtil.closeIO(fr, null); 33 } 34 //下面写字符输出流:就是把内存的数据存储到硬盘中去 35 36 37 } 38 39 }
标签:11,fr,22,read,FileReader,IOException,2022,new From: https://www.cnblogs.com/puwei520/p/16916716.html