Can anyone explain to me why this would throw an EofException? It really doesn't make sense to me.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| public void setSaveFile(File saveFile) { this.saveFile = saveFile; try { saveFile.createNewFile(); if(!isClosed && in != null) { in.close(); out.close(); } in = new ObjectInputStream(new FileInputStream(saveFile)); out = new ObjectOutputStream(new FileOutputStream(saveFile)); } catch(IOException e) { e.printStackTrace(); } } |
Basically, I'm trying to load a save file from the directory "data". When the file does not exist in this folder, I create a new one. When I do this, however, this exception gets thrown.
1 2 3 4 5
| java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source) at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source) at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) |
This exception does not get thrown when the file already exists. Any suggestions?