import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Goods implements Serializable{
private static final long serialVersionUID = -570535892820945589L;
private String id;
private String name;
private double price;
public Goods(String id, String name, double price) {
this.id = id;
this.name = name;
this.price = price;
}
public String toString() {
return "Goods [id=" + id + ", name=" + name + ", price=" + price + "]";
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
Goods goods_in = new Goods("10001", "JAVA", 39.90);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File("c://Goods")));
oos.writeObject(goods_in);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(new File("c://Goods")));
Goods goods_out = (Goods)ois.readObject();
ois.close();
System.out.println(goods_out.toString());;
}
}