【发布时间】:2016-04-14 21:59:59
【问题描述】:
我有一个大的二进制文件,我正在尝试使用 ObjectStream 从文件中读取。我收到错误
java.io.StreamCorruptedException: invalid stream header: 00000000
at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806)
at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299)
at demo.FileRead.readFile(FileRead.java:16)
我从文件中读取的代码是:
public static void readFile() throws FileNotFoundException, IOException, ClassNotFoundException {
FileInputStream inFile = new FileInputStream(new File("/home/xyz/Documents/packets_in_store_stats"));
ObjectInputStream ois = new ObjectInputStream(inFile);//Receive error at this point
DataAvailable[] ia = (DataAvailable[]) (ois.readObject());
System.out.println(ia[0] + "," + ia[1] + "," + ia[2] + "," + ia[3]
+ "," + ia[4]);
}
我是不是错过了什么。
【问题讨论】:
-
文件是否以 hexa
CAFEBABE开头?我感觉您要读取的文件不是序列化对象,而是其他东西(可能是另一种二进制格式)。您能分享一下您从哪里获得该文件或该文件是如何创建的吗? -
@Augusto 不,文件以 00000000 开头。它在异常中。
标签: java binaryfiles objectinputstream