why show me the last object i put in txt
<p>I have a big problem , I write in a txt file same objects Accounts when i click to see all objects i have write in txt is show me the last one only and how i show up the account in JOptionPane , the second is how i can make the account to take nuber one ,two , three...... every account i write to take a number plus one from the precedent account .
I believ to explain apparent</p>

<pre><code> if( str.equals("Receipt") )
 {
      ObjectInputStream in = null;
      Account acc = null;
      try
      {
           in = new ObjectInputStream(new FileInputStream("Accounts.txt"));
           while( (acc = (Account) in.readObject()) !=null)
           {
                if (acc instanceof Account)
                     ((Account)acc).print();
                //acc.print();
           }
      }
      catch(EOFException ex)
      {
           System.out.println("End of file reached.");
      }
      catch(ClassNotFoundException ex)
      {
           System.out.println("Error casting");
           ex.printStackTrace();
      }
      catch(FileNotFoundException ex)
      {
           System.out.println("Error specified file does not exist");
           ex.printStackTrace();
      }
      catch(IOException ex)
      {
           System.out.println("Error with I/O processes");
           ex.printStackTrace();
      }
      finally
      {
           try
           {
                in.close();
           }
           catch(IOException ex)
           {
                System.out.println("Another IOException during the closing");
                ex.printStackTrace();
           }
      }
 }
</code></pre>

<p>code to write object in file</p>

<pre><code>Account ac=new Account(posoOfil,poso,ariLoga,aitiol,diafor); 
      ac.print();

      try{

      OutputStream file = new FileOutputStream("Accounts.txt");
      OutputStream buffer = new BufferedOutputStream( file );
      ObjectOutput output = new ObjectOutputStream( buffer );
      try{
        output.writeObject(ac);
        output.flush();

System.out.println("Object written to file");
      }
      finally{
        output.close();
      }
    }
      catch
(FileNotFoundException ex) {System.out.println("Error with specified file") ;
ex.printStackTrace();}

    catch(IOException ex){
      System.out.println("Cannot perform output.");
    }

      }
</code></pre>

<p>And the class Account</p>

<pre><code>public class Account implements Serializable {

    private int arithmKat;
 // private Date date ;
    private int posoOfil;
    private int posoKat;
    private String ariLoga ;
    private String aitiol;
    private boolean diafor=false;

    public Account(int posoOfil, int posoKat,String ariLoga,String aitiol,boolean diafor){
    arithmKat++;
    this.posoOfil=posoOfil;
    this.posoKat=posoKat;
    this.ariLoga=ariLoga;
    this.aitiol=aitiol;
    this.diafor=diafor;

    }
    void print(){
    System.out.println(arithmKat+"  "+posoOfil+"  "+posoKat+"  "+diafor);}

}
</code></pre>
