标签:dem exce object close div 对象 amd 网络 throw
使用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();
}
}
标签:dem exce object close div 对象 amd 网络 throw
原文地址:http://www.cnblogs.com/newlangwen/p/7429411.html