我有一个大的二进制文件,我试图使用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]);
}
我在这里错过了什么。
答案 0 :(得分:0)
二进制文件不是序列化的对象流,除非你不知道,无论你怎么想,这个都不是。您应该使用DataInputStream
,而不是ObjectInputStream
,或者查看您编写文件的方式。