package com.shujia.day17.ketang;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
/*
字符缓冲输入流:BufferedInputStream
构造方法:
BufferedInputStream(InputStream in) 创建一个 BufferedInputStream并保存其参数,输入流 in ,供以后使用。
*/
public class BufferedInputStreamDemo1 {
public static void main(String[] args) throws Exception{
//创建一个字节缓冲输入流对象读取数据
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("src/com/shujia/day17/data/a1.txt"));
//一次读取一个字节
// int i = 0;
// while ((i=bis.read())!=-1){
// System.out.print((char) i);
// }
//一次读取一个字节数组
byte[] bytes = new byte[1024];
int length = 0;
while ((length=bis.read(bytes))!=-1){
String s = new String(bytes, 0, length);
System.out.print(s);
}
//释放资源
bis.close();
}
}
标签:String,BufferedInputStream,缓冲,day17,new,bis
From: https://www.cnblogs.com/qiwei-bigdata/p/18363509