package com.javase.io; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * FileReader: * 文件字符输入流,读取文本文件时比较方便快捷。 */ public class FileReaderText { public static void main(String[] args) { FileReader reader = null; try { reader = new FileReader("myfile"); // 准备一个char数组,(字节流中需要new byte[]数组) char[] chars = new char[4]; int readCount = 0; while ((readCount = reader.read(chars)) != -1){ System.out.print(new String(chars,0,readCount)); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } } }
FileReader文件字符输入流
于 2022-12-24 12:47:13 首次发布