首页 > 其他分享 >字节输入流读数据 使用字节数组

字节输入流读数据 使用字节数组

时间:2022-12-15 16:31:53浏览次数:39  
标签:字节 io bytes len 读数据 数组 FileInputStream fileInputStream

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Test4 {
public static void main(String[] args) throws IOException {
// 获得字节输入流对象
FileInputStream fileInputStream = new FileInputStream("a.txt");
// 获取数据
byte[] bytes = new byte[4];
int len = fileInputStream.read(bytes);
// 遍历
while (len != -1) {
// 遍历字节数组 获取字节成员
for (int i = 0; i < len; i++) {
byte b = bytes[i];
System.out.println(b);
}
// 重新获取一下数据 更新len的值
len = fileInputStream.read(bytes);
}
// 关闭资源
fileInputStream.close();

System.out.println("game over");
}
}

标签:字节,io,bytes,len,读数据,数组,FileInputStream,fileInputStream
From: https://blog.51cto.com/u_13137233/5940250

相关文章