首页 > 其他 > 详细

缓冲区输入流

时间:2021-02-22 12:09:14      阅读:21      评论:0      收藏:0      [点我收藏+]

缓冲区输入流也和文件输入流差不多,直接看代码:

 1 package com.hw.file0221;
 2 
 3 import java.io.BufferedInputStream;
 4 import java.io.FileInputStream;
 5 import java.io.FileNotFoundException;
 6 import java.io.IOException;
 7 
 8 public class Demo02TestBufferedInputStream {
 9     public static void main(String[] args) {
10         
11         BufferedInputStream input = null;
12         FileInputStream fileinput;
13         try {
14             fileinput = new FileInputStream("F://骚操作//demotest01.txt");
15             input = new BufferedInputStream(fileinput);
16             
17             int data = input.read();  //按字节
18             System.out.println((char)data);
19             data = input.read();
20             System.out.println((char)data);
21             data = input.read();
22             System.out.println((char)data);
23             
24             byte[] info = new byte[1024];   //按数组
25             int length = input.read(info);
26             String str = new String(info,0,length);
27             System.out.println(str);
28             
29         } catch (IOException e) {
30             // TODO Auto-generated catch block
31             e.printStackTrace();
32         }finally{
33             try {
34                 if(input != null){
35                     input.close();
36                 }
37             } catch (IOException e) {
38                 // TODO Auto-generated catch block
39                 e.printStackTrace();
40             }
41         }
42     }
43 }

读取文件也是可以按字节或者按照字节数组来。

技术分享图片

 

 

缓冲区输入流

原文:https://www.cnblogs.com/EvanTheGreat/p/14428677.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!