Serializable读写类操作

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.WriteAbortedException;

public class Serializable_test {

	public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
		stu stu=new stu(121, "eqwewq");
		
		
//		Writeobj(stu);
		resetobj();
	}

	public static void resetobj() throws ClassNotFoundException, IOException {
		ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("E:\\123.txt"));
		Object object=objectInputStream.readObject();
		stu stu2=(stu)object;
		System.out.println(stu2);
		objectInputStream.close();
	}

	public static void Writeobj(stu stu) throws IOException {
		ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("E:\\123.txt"));
		objectOutputStream.writeObject(stu);
		objectOutputStream.close();
		
	}

}

  

posted @ 2019-06-21 14:42  黑魔法os  阅读(264)  评论(0编辑  收藏  举报