对象VS字符(节流)
//以下是把integer类型转化成byte[]数组类型,同理可以使用引用对象
public static void main(String[] args) {
ObjectOutputStream oos = null;//对象输出流
ByteArrayOutputStream baos = null;//byte数组输出流
ByteArrayInputStream bais = null;//对象输入流
try {
//序列化
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);//将数组流传入对象流
oos.writeObject(new Integer(1));//用对象流读取对象。
byte[] bytes = baos.toByteArray();//用数组流将传入的对象转化为byte数组
//反序列化
bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);
Integer i = (Integer)ois.readObject();
System.out.println(i);
} catch (Exception e) {
e.printStackTrace();
}
}