StremCorrupted Exception reading on an object
hi guys i m getting StreamCorruptedException just don't know why. its a simple program. below is my main class.package Basics1;
import java.util.*;
import java.io.*;
publicclass UseStaticIpData{
public UseStaticIpData(){
}
publicstaticvoid main(String[] args)throws IOException{
StaticIpData sipd =new StaticIpData();
FileIpData fipd =new FileIpData();
ArrayList al =new ArrayList();
for(int i=0;i<3;i++){
sipd.setIp1(i);
sipd.setIp2(i);
sipd.setIp3(i);
sipd.setIp4(i);
fipd.setStaticIpData(sipd);
}al = fipd.getStaticIpDataAsList();
Iterator ir = al.iterator();
while(ir.hasNext()){
System.out.println(((StaticIpData)ir.next()).getIpAsString());
}
}
}
and the two helper classespackage Basics1;
import java.io.*;
import java.util.*;
publicclass FileIpData{
StaticIpData sipd =new StaticIpData();
public FileIpData(){
}
publicvoid setStaticIpData(StaticIpData si){
try{
ObjectOutputStream oos =new ObjectOutputStream(new FileOutputStream("data.txt",true));
oos.writeObject(si);
oos.flush();
oos.close();
}catch(FileNotFoundException fnfe){
System.out.println("called out fnfe");
}catch(IOException ioe){
System.out.println("called out ioe");
}finally{
}
}
public ArrayList getStaticIpDataAsList()throws IOException{
ArrayList al =new ArrayList();
ObjectInputStream ois;// = new ObjectInputStream(new FileInputStream("data.txt"));
try{
ois =new ObjectInputStream(new FileInputStream("data.txt"));
while(true){
al.add((StaticIpData)ois.readObject());
}
//ois.close();
}catch(EOFException eofe){
System.out.println("called in eof");
}catch(FileNotFoundException fnfe){
System.out.println("called in fnfe");
}catch(ClassNotFoundException cnfe){
System.out.println("called in cnfe");
}finally{
}
return al;
}
}
and this onepackage Basics1;
import java.io.*;
import java.util.*;
publicclass FileIpData{
StaticIpData sipd =new StaticIpData();
public FileIpData(){
}
publicvoid setStaticIpData(StaticIpData si){
try{
ObjectOutputStream oos =new ObjectOutputStream(new FileOutputStream("data.txt",true));
oos.writeObject(si);
oos.flush();
oos.close();
}catch(FileNotFoundException fnfe){
System.out.println("called out fnfe");
}catch(IOException ioe){
System.out.println("called out ioe");
}finally{
}
}
public ArrayList getStaticIpDataAsList()throws IOException{
ArrayList al =new ArrayList();
ObjectInputStream ois;// = new ObjectInputStream(new FileInputStream("data.txt"));
try{
ois =new ObjectInputStream(new FileInputStream("data.txt"));
while(true){
al.add((StaticIpData)ois.readObject());
}
//ois.close();
}catch(EOFException eofe){
System.out.println("called in eof");
}catch(FileNotFoundException fnfe){
System.out.println("called in fnfe");
}catch(ClassNotFoundException cnfe){
System.out.println("called in cnfe");
}finally{
}
return al;
}
}
please help i've been stuck for 2 days now and unable to find a solution. also api doesn't explain much why streamsgetcorrupted

