package itcast.java16; import java.io.FileReader; import java.io.IOException; /* * (字符数组读取方式二) */ public class FileReaderDemo2 { public static void main(String[] args) { FileReader fr = null; try { fr = new FileReader("demo.txt"); char[] chars = new char[1024]; int i = 0; while ((i = fr.read(chars)) != -1) { System.out.println(String.valueOf(chars, 0, i)); } } catch (IOException e) { e.printStackTrace(); } finally { if (fr != null) try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } } }