import java.io.*;
import java.util.*;
class book implements Serializable
{
public String name;
public String author;
public String price;
public String publisher;
public book(String n,String a,String p,String pu)
{
name=n;
author=a;
price=p;
publisher=pu;
}
public String toStirng()
{
return "书名:"+name+"\n"+"作者:"+author+"\n"+"价格:$"+price+"\n"+"出版社:"+publisher+"\n";
}
}
public class Trybook
{
public static void main(String[] args) throws IOException
{
try
{ book[] shu=new book[3];
shu[0]=new book("操作系统","郑扣根","55","高等教育出版社");
shu[1]=new book("面向对象程序设计","叶乃文","33","清华大学出版社");
shu[2]=new book("计算机组成原理","白中英","33","科学出版社");
ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream("e:/book.txt"));
out.writeObject(shu);
out.close();
ObjectInputStream in=new ObjectInputStream(new FileInputStream("e:/book.txt"));
book[] newshu=(book[])in.readObject();
for(int i=0;i<newshu.length;i++) System.out.println(newshu[i].toStirng());
}catch(Exception e){
System.out.println("Error:"+e);
System.exit(1);
}
}
}