ArrayList 的序列化

List<Date> list=new ArrayList<Date>();
  Date now=new Date();
  list.add(now);
  list.add(new Date(now.getTime()+8888888));
  ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
  ObjectOutput output=new ObjectOutputStream(byteStream);
  output.writeObject(list);
  byte b[]=byteStream.toByteArray();
  BASE64Encoder base64Encoder=new BASE64Encoder();
  String cookieString=base64Encoder.encode(b);
  System.out.println("经过BASE64编码的Cookie:\n"+cookieString);
  System.out.println("\n开始解码");
  BASE64Decoder base64Decoder=new BASE64Decoder();
  byte buf[]=base64Decoder.decodeBuffer(cookieString);
  ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(buf);
  ObjectInput input=new ObjectInputStream(byteArrayInputStream);
  List<Date> afterList=(List<Date>) input.readObject();  
  for (Date date : afterList) {System.out.println(date);}

你可能感兴趣的:(ArrayList)