字符输入流遍历读数据 使用字符数组容器 1216

import java.io.FileInputStream;import java.io.IOException;import java.io.InputStreamReader;public class Test4 { public static void main(String[] args) throws IOException { // 获得字节输入流 FileInputStream xs = new FileInputStream(“小说.txt”); // 获得字符输入流 InputStreamReader isr = new InputStreamReader(xs); // 获得一个字符容器 char[] chars = new char[4]; // 开始遍历读数据 int len = isr.read(chars); while (len != -1) { // 从容器中取数据 String msg = new String(chars, 0, len); System.out.print(msg); len = isr.read(chars); } // 关闭资源 xs.close(); isr.close(); // 程序结束 System.out.println(“game over”); }} 昨晚多几分钟的准备,今天少几小时的麻烦。

字符输入流遍历读数据 使用字符数组容器 1216

相关文章:

你感兴趣的文章:

标签云: