import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class TestSerilizible {
/**
* @param args
*/
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
FileOutputStream fos = new FileOutputStream("abc.txt");
ObjectOutputStream oos=new ObjectOutputStream(fos);
Person p=new Person();
p.setName("asd");
oos.writeObject(p);
oos.flush();
FileInputStream fis=new FileInputStream("abc.txt");
ObjectInputStream ois=new ObjectInputStream(fis);
Person p1=(Person)ois.readObject();
System.out.println(p1.getName());
ois.close();
oos.close();
}
}
class Person implements Serializable
{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
private String pwd;
} |