package cn.itcast_03;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
/*
* InputStreamReader的方法:
* int read():一次读取一个字符
* int read(char[] chs):一次读取一个字符数组
*/
public class InputStreamReaderDemo {
public static void main(String[] args) throws IOException {
// 创建 对象
InputStreamReader isr = new InputStreamReader(new FileInputStream(
"StringDemo.java"));
// 读取数据
// int read():一次读取一个字符
// int ch = 0;
// while ((ch = isr.read()) != -1) {
// System.out.print((char) ch);
// }
// int read(char[] chs):一次读取一个字符数组
char[] chs = new char[1024];
int ch = 0;
while ((ch = isr.read(chs)) != -1) {
System.out.print(new String(chs, 0, ch));
}
// 释放资源
isr.close();
}
}
IO流_字符流的2种读数据的方式
最新推荐文章于 2022-05-19 17:34:31 发布