using Object input\ output Streams with files and array list

Posted by soad el-hayek on Stack Overflow See other posts from Stack Overflow or by soad el-hayek
Published on 2010-05-29T20:39:20Z Indexed on 2010/05/29 20:42 UTC
Read the original article Hit count: 253

Filed under:
|

hi every one ..

i'm an it student , and it's time to finish my final project in java , i've faced too many problems , this one i couldn't solve it and i'm really ubset ! :S

my code is like this :

in Admin class : public ArrayList cos_info = new ArrayList(); public ArrayList cas_info = new ArrayList(); public int cos_count = 0 ; public int cas_count = 0 ;

        void coustmer_acount() throws FileNotFoundException, IOException{ 
       String add=null; 
       do{ 
          person p = new person() ; 
          cos_info.add(cos_count, p); 
          cos_count ++ ; 
          add =JOptionPane.showInputDialog("Do you want to add more   coustmer..\n'y'foryes ..\n 'n'for No .."); 
   } 

          while(add.charAt(0) == 'Y'||add.charAt(0)=='y'); 
          writenew_cos(); 
          // add_acounts(); 
          } 

      void writenew_cos() throws IOException{ 
       ObjectOutputStream aa = new ObjectOutputStream(new FileOutputStream("coustmer.txt")); 
       aa.writeObject(cos_info); 
      JOptionPane.showMessageDialog(null,"Added to file done sucessfuly.."); 
       aa.close(); 
    } 

in Coustmer class :

  void read_cos() throws IOException, ClassNotFoundException{ 
    person p1= null ;
    int   array_count = 0;
    ObjectInputStream d = new ObjectInputStream(new FileInputStrea ("coustmer.txt")); 
    JOptionPane.showMessageDialog(null,d.available() );
   for(int i = 0;d.available() == 0;i++){
      a.add(array_count,(ArrayList) d.readObject());
      array_count++; 
      JOptionPane.showMessageDialog(null,"Haaaaai :D" );
      JOptionPane.showMessageDialog(null,array_count );
      } 
      d.close();
      JOptionPane.showMessageDialog(null,array_count +"1111" );
        for(int i = 0 ; i<a.size()&& found!= true ; i++){
            count++ ;
            p1 =(person)a.get(i);
            user=p1.user;
            pass = p1.pass;
            cas_checkpass();
                                }
      }

it just print JOptionPane.showMessageDialog(null,d.available() ); and having excep. here a.add(array_count,(ArrayList) d.readObject()); p.s : person object from my own class and it's Serializabled

© Stack Overflow or respective owner

using Object input\ output Streams with files and array list

Posted by soad el-hayek on Stack Overflow See other posts from Stack Overflow or by soad el-hayek
Published on 2010-05-29T19:50:59Z Indexed on 2010/05/29 19:52 UTC
Read the original article Hit count: 253

Filed under:
|

hi every one ..

i'm an it student , and it's time to finish my final project in java , i've faced too many problems , this one i couldn't solve it and i'm really ubset ! :S

my code is like this :

in Admin class : public ArrayList cos_info = new ArrayList(); public ArrayList cas_info = new ArrayList(); public int cos_count = 0 ; public int cas_count = 0 ;

void coustmer_acount() throws FileNotFoundException, IOException{
String add=null;
 do{
    person p = new person() ;
    cos_info.add(cos_count, p);
    cos_count ++ ;
     add =JOptionPane.showInputDialog("Do you want to add more  coustmer..\n'y'foryes ..\n 'n'for No ..");
     }

   while(add.charAt(0) == 'Y'||add.charAt(0)=='y');
   writenew_cos();
  // add_acounts();
   }

    void writenew_cos() throws IOException{
    ObjectOutputStream aa = new ObjectOutputStream(new FileOutputStream("coustmer.txt"));
    aa.writeObject(cos_info);
    JOptionPane.showMessageDialog(null,"Added to file done sucessfuly..");
    aa.close();
     }

in Coustmer class :

void read_cos() throws IOException, ClassNotFoundException{ person p1= null ; int array_count = 0; ObjectInputStream d = new ObjectInputStream(new FileInputStream("coustmer.txt")); JOptionPane.showMessageDialog(null,d.available() ); for(int i = 0;d.available() == 0;i++){ a.add(array_count,(ArrayList) d.readObject()); array_count++; JOptionPane.showMessageDialog(null,"Haaaaai :D" ); JOptionPane.showMessageDialog(null,array_count ); } d.close(); JOptionPane.showMessageDialog(null,array_count +"1111" ); for(int i = 0 ; i

it just print JOptionPane.showMessageDialog(null,d.available() ); and having excep. here a.add(array_count,(ArrayList) d.readObject()); p.s : person object from my own class and it's Serializabled

© Stack Overflow or respective owner

Related posts about arraylist

Related posts about filestream