zoukankan      html  css  js  c++  java
  • 对象序列化到本地文件 ObjectOutputstream ObjcetInputstream

    package com.main.test;
    
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    
    public class ObjectOutputStreamDemo {
    
    	public static void main(String[] args) throws ClassNotFoundException {
    		// TODO Auto-generated method stub
             //  ObjectOutPutStreamDemo();
    		try {
    		ObjectInputStream ois = new ObjectInputStream(new FileInputStream("c:\OOS.txt"));
    		Object readObject = ois.readObject();
    		Person person = (Person)readObject;
    		System.out.println(person.toString());
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
               
    	}
    
    	private static void ObjectOutPutStreamDemo() {
    		try {
    			ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("c:\OOS.txt"));
    			Person person = new Person("zhangsan",12);
    			oos.writeObject(person);
    			System.out.println(person.toString());
    			
    			oos.close();
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    	}
    
    }
    

      

  • 相关阅读:
    【CF617D】Roads in Yusland
    对偶问题
    【LG3722】[HNOI2017]影魔
    [HEOI2017] 相逢是问候
    [SHOI2009] 会场预约
    [SCOI2007] 修车
    [CTSC2008] 网络管理
    [国家集训队] 礼物
    [Poetize6] IncDec Sequence
    [网络流24题] 魔术球问题
  • 原文地址:https://www.cnblogs.com/childhooding/p/4788231.html
Copyright © 2011-2022 走看看