Read Object and Write Object:
public class Emp implements Serializable{
String name;
int marks;
String address;
public Emp(){
}
public Emp(String name,int marks, String address)
{
this.name=name;
this.marks=marks;
this.address=address;
}
public String disp() {
return name+"\t"+marks+"\t"+address;
}
}
ObjectWriterClass
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("d:/nkser.txt"));
Emp e=new Emp("raju", 300, "patan");
Emp e1=new Emp("raj", 200, "patan");
out.writeObject(e);
out.writeObject(e1);
out.close();
Object ReaderClass
ObjectInputStream in=new ObjectInputStream(new FileInputStream("d:/nkser.txt"));
Emp e=(Emp) in.readObject();
Emp e1=(Emp) in.readObject();
System.out.println(e.disp());
System.out.println(e1.disp());
in.close();
No comments:
Post a Comment