Questions tagged [eofexception]

An exception that occurs when reading from a stream or file, and indicates that the end of the stream has been reached. For example, you had expected to read 4 bytes from a stream with DataInputStream.readFully(), or an object with ObjectInputStream.readObject(), but end of stream was encountered instead.

An exception that occurs when reading from a stream or file, and indicates that the end of the stream has been reached. For example, you had expected to read 4 bytes from a stream with DataInputStream.readFully(), or an object with ObjectInputStream.readObject(), but end of stream was encountered instead.

Even though the exception is named EOF for 'end of file', it is possible to get this exception when processing any data stream. The exception can occur as a result of many different actions, such as:

  1. Reading data from a socket connection that has already been closed by the peer and all prior pending data has already been read.
  2. Reading data from an empty file.

When reading from a stream, you should usually detect and handle this exception, as well as other stream-related exceptions such as timeouts, by wrapping your reads in a try-catch block. This will allow you to catch exceptions such as this, and perform an alternate operation, such as alerting the user of the error, or ending the logical connection at this end.

214 questions
-1
votes
3 answers

After EOFException variable=null

If I end the client session a EOFException is thrown but I read that this would be normal so I just start a new thread with the same functionality but the value of Restaurant=null; although i wrote it in a .txt file public void run(){ try { …
Sebastian Walla
  • 1,104
  • 1
  • 9
  • 23
-1
votes
3 answers

(Java) EOFException when reading from a Text File

I am reading two strings and a double from a text file, but keep throwing an EOFException. This is my code: public static Book readBook(String pathname) throws IOException, FileNotFoundException{ DataInputStream dis = new DataInputStream( …
Kamon241
  • 75
  • 1
  • 4
  • 11
-2
votes
1 answer

EOFException when obtaining a Writer object on serilized file

I am getting following: java.io.EOFException at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source) at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source) at…
Twaha Mehmood
  • 737
  • 3
  • 9
  • 26
-3
votes
1 answer

EOFException while calling ObjectInputStream.readObject()

I need to get a hashmap from a hex string I've serialized. Currently, I can get the hashmap, but it creates an EOFException. private static String writeMaterialMap(HashMap map) throws Exception { System.out.print(map); …
Sage M
  • 119
  • 1
  • 2
  • 9
1 2 3
14
15