黑马程序员-JAVA高级视频_IO输入与输出-18天-6(文本文件读取方式二)
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(); } } } }