首页 > 其他分享 >字符输入流遍历读数据 使用字符数组容器 1216

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

时间:2022-12-16 15:41:15浏览次数:52  
标签:字符 1216 isr chars len 读数据 io FileInputStream new

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,isr,chars,len,读数据,io,FileInputStream,new
From: https://blog.51cto.com/u_13137233/5947528

相关文章