本帖最后由 陈欢 于 2012-7-20 00:41 编辑
在JAVA解序列化中,如何读取bk1的private变量,不太明白
public static void main(String[] args) throws IOException, ClassNotFoundException {
try{
Book bk=new Book(0010,"JAVA学习基础","张宇",45.80);
FileOutputStream fo=new FileOutputStream("book.dat");
ObjectOutputStream oo=new ObjectOutputStream(fo);
oo.writeObject(bk);
oo.close();
FileInputStream fi=new FileInputStream("book.dat");
ObjectInputStream oi=new ObjectInputStream(fi);
Book bk1=(Book)oi.readObject();
}
}
catch(IOException e){
System.out.println("I/O Exception");
}
} }
class Book implements Serializable {
private int m_id;
private String m_name;
private String m_author;
double m_price;
public Book(int id, String name, String author, double price) {
m_id = id;
m_name = name;
m_author = author;
m_price = price;
}
} |
|