本文共 624 字,大约阅读时间需要 2 分钟。
一次读一个字节数组的方法
public int read(byte[] b):从输入流读取最多b.length个字节的数据
返回的是读入缓冲区的总字节数,也就是实际的读取字节个数
示例代码
public class FileInputStreamDemo02 { public static void main(String[] args) throws IOException { //创建字节输入流对象 FileInputStream fis = new FileInputStream("myByteStream\\fos.txt"); /* hello\r\n world\r\n 第一次:hello 第二次:\r\nwor 第三次:ld\r\nr */ byte[] bys = new byte[1024]; //1024及其整数倍 int len; while ((len=fis.read(bys))!=-1) { System.out.print(new String(bys,0,len)); } //释放资源 fis.close(); }}
转载地址:http://cryzb.baihongyu.com/