import java.io.*;
public class SGH
{
public static void writeToFile(Book b[],int n)throws Exception{
FileOutputStream fout=new FileOutputStream("book.dat");
ObjectOutputStream oout=new ObjectOutputStream(fout);
for(int i=0;i oout.writeObject(b[i]); } oout.close(); } public static Book[]readFromFile(int n)throws Exception{ Book Book1[]=new Book[n]; FileInputStream fin=new FileInputStream("book.dat"); ObjectInputStream oin=new ObjectInputStream(fin); for(int i=0;i Book1[i]=(Book)oin.readObject(); } oin.close(); return Book1; } public static void main(String args[])throws Exception { Book Book1[]=new Book[3]; for(int i=0;i<3;i++){ Book1[i]=new Book((3+i),("书"+(i))); } Book Book2[]; writeToFile(Book1,3); Book2=readFromFile(3); } } class Book implements Serializable { public float price; public String bookName; public Book(float p,String b) { this.price=p; this.bookName=b;