字节输入流读数据 使用字节数组
发布时间:2022-12-19 13:34:14 267 相关标签: # java# java# 数据
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");
}
}
文章来源: https://blog.51cto.com/u_13137233/5940250
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报