對象的持久化存儲

package cn.itcast.p2.io.object;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;

import cn.itcast.p2.io.Person.Person;

public class ObjectDemo {

	public static void main(String[] args) throws IOException, IOException {
		
		ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("1.object"));
		
		oos.writeObject(new Person("小強",23));
		oos.close();
	}

}




package cn.itcast.p2.io.Person;

import java.io.Serializable;

public class Person implements Serializable {
	private String name;
	private int age;
	public Person(String name, int age) {
		super();
		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;
	}
	
}
相關文章
相關標籤/搜索