import java.io.FileInputStream;标签:字节,io,bytes,len,读数据,数组,FileInputStream,fileInputStream From: https://blog.51cto.com/u_13137233/5940250
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");
}
}