• Post Reply Bookmark Topic Watch Topic
  • New Topic

Got Exception in File Reading  RSS feed

 
Bharathi Dhas Krishnasamy
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Exception in thread "main" java.io.EOFException
at java.io.DataInputStream.readFully(DataInputStream.java:180)
at java.io.DataInputStream.readUTF(DataInputStream.java:592)
at java.io.DataInputStream.readUTF(DataInputStream.java:547)
at javatestrun.Main.main(Main.java:17)

Any can tell reason?
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you write a String to that file using DataOutputStream's writeUTF method? I don't think so. It's probably a regular text file. In that case you should use a FileReader wrapped in a BufferedReader to read text data from it.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Rob says, class DataInputStream is not meant for reading plain text files. It expects a special input format. The API documentation of the method readUTF() in interface java.io.DataInput explains what that format looks like - it is very different from a plain text file.

Use other classes than DataInputStream to read the file - Rob already gave some hints.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!