缓冲字节输入流BufferedInputStream
程序员文章站
2024-03-06 16:30:32
...
1.在e盘下创建aaa.txt
1.代码
package d01_TestInput;/*
* zt
* 2020/8/7
* 11:31
*
*/
import java.io.BufferedInputStream;
import java.io.FileInputStream;
public class TestBufferedInputStream {
public static void main(String[] args) throws Exception {
FileInputStream fis = new FileInputStream("e:\\aaa.txt");
BufferedInputStream bis = new BufferedInputStream(fis);
/*//2.单个读取
int data = 0;
while((data=bis.read())!=-1){
System.out.println((char)data);
}*/
//2.1多个字节读取
byte[] buf = new byte[1024];
int len =0;
while ((len=bis.read(buf))!=-1){
System.out.println(new String(buf,0,len));
}
//3.关闭缓冲流会自动关闭节点流
bis.close();
}
}
2.输出结果
归来是诗,离去成词,且笑风俗,不敢放肆
归来是诗,离去成词,且笑风俗,不敢放肆
Process finished with exit code 0