zoukankan      html  css  js  c++  java
  • java 序列化和反序列化数据

    使用ObjectOutputStream 序列号原始数据和对象数据,使用ObjectInputStream 反序列化

    使用字节存储数据,可以将序列化的数据存储到硬盘上,或输出到网络上

    package com.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;
    import java.util.Date;
    
    public class ObjecyOutputStreamDemo {
    
    	public static void main(String[] args) throws IOException, ClassNotFoundException {
            out();
    		in();
    		
    	}
        public static void out() throws IOException{
        	FileOutputStream fileOutputStream = new FileOutputStream("F:/a.txt");
    		ObjectOutputStream oos = new ObjectOutputStream(fileOutputStream);
    		oos.writeInt(124);
    		oos.writeObject("Today");
    		oos.writeObject(new Date());
    		oos.close();
    		
    		
        }
        public static void in() throws IOException, ClassNotFoundException{
        	FileInputStream in = new FileInputStream("F:/a.txt");
        	ObjectInputStream ois = new ObjectInputStream(in);
        	 int i = ois.readInt();
             String today = (String) ois.readObject();
             Date date = (Date) ois.readObject();
             System.out.println(i+today+date);
        	ois.close();
        }
    }
    

      

  • 相关阅读:
    PHP header函数设置http报文头示例详解
    在Windows下为PHP安装redis扩展
    CMD模拟http请求
    strstr使用
    memset使用
    QT修改应用程序图标
    纪念下自学QT 第十天 终于写成了串口调试助手
    QT设置textEdit光标到末尾
    QT设置TextEdit颜色
    QT设置QToolBar带有图标和文字
  • 原文地址:https://www.cnblogs.com/newlangwen/p/7429411.html
Copyright © 2011-2022 走看看