其他分享
首页 > 其他分享> > 字节输入流一次读取多个字节

字节输入流一次读取多个字节

作者:互联网

字节输入流一次读取多个字节

  read(byte),从输入流中读取一定数量的字节,并将其存储在缓存区数组B中

  明确两件事:

    方法参数中,byte[] 的作用是什么??

    方法的返回值int 是什么?

案例:

  

 

 我们可以方法,这个读取是一个重复的过程,那么我们可以使用循环来读取

我们不知道有多少个字节,所以来使用while字节

结束调节 读到-1结束

案例:

  

    public static void main(String[] args) throws IOException {
//   1,创建FileInputStream对象,构造方法中要绑定数据源
FileInputStream is = new FileInputStream("aa.txt");
int len =0;
while ((len=is.read())!=-1){
System.out.println((char) len);
}
is.close();

}
}

 

标签:字节,int,len,read,FileInputStream,输入,读取
来源: https://www.cnblogs.com/ssr1/p/16490761.html