Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EOF Exception  RSS feed

 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i am facing the exception EOF whenever i run my program and compiler indicates that the problem is on that statement
Object obj;
While((obj = us.readObject())!=null)
{
...
...
...
}
waiting for response.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For a better response, you might want to also post the exception you are getting along with its stack trace..

 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.io.*;
import java.util.*;
public class Read
{
public static void main(String args[]) throws Exception
{
FileInputStream fs = new FileInputStream("p2.txt");
ObjectInputStream os = new ObjectInputStream(fs);
Object obj = os.readObject();
while(obj!=null)
{
if(obj instanceof Program1)
{
Program1 p = (Program1) obj;
System.out.println(p);
}
else if(obj instanceof Program2)
{
Program2 p = (Program2) obj;
System.out.println(p);
}
obj = os.readObject();
}
os.close();
fs.close();
}
}



Name: Salman MushtaqAge : 22
Name: Farzan MehdiAge : 22
Exception in thread "main" java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
at java.io.ObjectInputStream.readObject0(Unknown Source)
at java.io.ObjectInputStream.readObject(Unknown Source)
at Read.main(Read.java:22)
Name: Salman MushtaqId : 22Gpa: 238
Name: Farzan MehdiId : 22Gpa: 33

 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can not consider any file contents as an object input stream, can you?

Where did the contents of the file come from? Not with hand prepared with say notepad?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!