Results 1 to 3 of 3

Thread: Serilization eror

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2005
    Posts
    9

    Serilization eror

    OBJ= (Add) din.readObject();
    while(OBJ!=null)
    {
    System.out.println(OBJ.s1);
    System.out.println(OBJ.s1);
    OBJ=(Add)din.readObject();
    }
    when i used the above code ihave got
    EOFException how i get end of file
    is there an other method
    and i have "next"
    button how i control the cursor mean
    how i get the next or privious record in
    the file
    thank in advance

  2. #2
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Serilization eror

    Instead of trying this:
    Code:
    if (obj != null)
    {
    }
    Try doing this:

    Code:
    if (obj != -1)
    {
    }
    Usually the end of file exceptions are thrown whenever a -1 is returned, signifying that it's the end of a file.

  3. #3
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    Re: Serilization eror

    It would help if you could provide more code. Plus why are you reading the object twice? You already have the object returned from readObject(). Here's some code which might help.
    Code:
    import java.io.*; 
     
     public class Y{
       public static void main(String[] args){
       ObjectInputStream oip = null;     
       try{
         oip = new ObjectInputStream(new FileInputStream("C:" + File.separator + "ObjSerFile")); 
         SerObj serobj = (SerObj)oip.readObject(); 
         System.out.println(serobj.getTemp());  
         System.out.println(serobj.getIndicator()); 
        }catch(Exception io){
           System.err.println(io);
        }finally{
       try{
        oip.close(); 
       }catch(IOException io){
         System.err.println(io);     
       } 
      }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width