Frage

So I have a program that is attempting to read in a file to fill in an ArrayList, but keep getting this error when I run the program:

java.io.StreamCorruptedException: invalid stream header: 69652E77

The code:

File saveList = new File("PlayerDatabase.dat");

if(saveList.exists())
{
    FileInputStream FileStream = new FileInputStream(saveList);
    ObjectInputStream ObjStream = new ObjectInputStream(FileStream);

    list = (List<Player>)ObjStream.readObject();
    ObjStream.close();
}
War es hilfreich?

Lösung

When you construct an ObjectInputStream, the constructor reads the first two bytes using readStreamHeader() from the stream expecting them to be the magic values that should be present in an object stream.

protected void readStreamHeader()
        throws IOException, StreamCorruptedException
    {
        short s0 = bin.readShort();
        short s1 = bin.readShort();
        if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
            throw new StreamCorruptedException(
                String.format("invalid stream header: %04X%04X", s0, s1));
        }
    }

Thus if it doesn't find either of them it throws the StreamCorruptedException as is evident from the source above. make sure that the file is written in correct format.

Andere Tipps

It seems file has not been serialized in correct format, so StreamCorruptedException is thrown while de-serialization.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top