对象流demo1: package com.etc.test; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; class Customer implements Serializable { private String name,ID; private String password; private float salary; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getID() { return ID; } public void setID(String iD) { ID = iD; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } public Customer(String name, String iD, String password, float salary) { super(); this.name = name; ID = iD; this.password = password; this.salary = salary; } } public class ObjectDemo { public static void main(String[] args) { try { ObjectOutputStream objectOut=new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("object.bin"))); Customer cus=new Customer("wen", "2", "rytf", 2300); objectOut.writeObject(cus); objectOut.close(); ObjectInputStream objectIn=new ObjectInputStream(new BufferedInputStream(new FileInputStream("object.bin"))); cus=(Customer) objectIn.readObject(); System.out.println("name:"+cus.getName()); System.out.println("id:"+cus.getID()); System.out.println("password:"+cus.getPassword()); System.out.println("salary:"+cus.getSalary()); } catch(NotSerializableException e) { System.out.println(e.getMessage()); } catch (ClassNotFoundException e) { System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e.getMessage()); } } } ========================================================================