public static void main(String[] args) throws Exception {
System.out.println(String.format("%1$tF %1$tT", Calendar.getInstance()));
//序列化
/*
List<Date> dateList=new ArrayList<Date>();
for(int i=0;i<1000000;i++){
dateList.add(Calendar.getInstance().getTime());
}
ObjectOutputStream oos=new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream("1.a"))); //100万 个日期对象生成的文件 45K
oos.writeObject(dateList);
oos.close();//注意一定要关闭
System.out.println("......");
*/
//反序列化
ObjectInputStream ois = new ObjectInputStream(new java.util.zip.GZIPInputStream(new FileInputStream("1.a")));
@SuppressWarnings("unchecked")
List<Date> obj = (List<Date>) ois.readObject();
ois.close();
System.out.println(String.format("%1$tF %1$tT", Calendar.getInstance()));
System.out.println(obj.size());
System.out.println(obj.get(0));
}
100万个日期对象序列化生成的文件45K
最新推荐文章于 2024-10-06 20:16:20 发布