using Object input\ output Streams with files and array list
- by soad el-hayek
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