标签:tin string cep div 重构 ble file 示例 str
public ObjectOutputStream(OutputStream out) throws IOException
public final void writeObject(Object obj) throws IOException
public ObjectInputStream(InputStream in) throws IOException
public final Object readObject() throws IOException, ClassNotFoundException
package java20; import java.io.Serializable; /** * 2017/10/15 * 说明: */ public class Person implements Serializable { private String name; private int age; public Person() { } public Person(String name, int age) { this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } }
package java20; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; /** * 2017/10/15 * 说明: */ public class ObjectOutputStreamDemo { public static void main(String[] args) throws IOException { ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("person.txt")); os.writeObject(new Person("张三",50)); os.close(); } }
package java20; import java.io.FileInputStream; import java.io.IOException; import java.io.ObjectInputStream; /** * 2017/10/15 * 说明: */ public class ObjectInputStreamDemo { public static void main(String[] args) throws IOException, ClassNotFoundException { ObjectInputStream oi = new ObjectInputStream(new FileInputStream("person.txt")); Person p = (Person) oi.readObject(); System.out.println(p.getName()); System.out.println(p.getAge()); } }
标签:tin string cep div 重构 ble file 示例 str
原文地址:http://www.cnblogs.com/xuweiweiwoaini/p/7673792.html