import java.util.*;
import java.io.*;public class Today{
   public static void main(String[] args){
      ObjectOutputStream out=null;
      try{
         out=new ObjectOutputStream(new FileOutputStream(new File("C:/date.dat")));
         out.writeObject(new Date());
         out.writeObject(new Long(System.currentTimeMillis()));//Object only
      }catch(Exception e){
      }finally{
         try{
            if(out!=null){out.close();}
         }catch(Exception e){}
      }
      ObjectInputStream in=null;
      try{
         in=new ObjectInputStream(new FileInputStream(new File("C:/date.dat")));
         Date date=(Date)in.readObject(); //读的顺序应与写时一致,并需转型
         System.out.println(date);
         Long millis=(Long)in.readObject();
         System.out.println(millis);
      }catch(Exception e){
      }finally{
         try{
            if(in!=null){in.close();}
         }catch(Exception e){}
      }
   }
}

解决方案 »

  1.   

    抄作业啊?是啊,谢谢     : shine333(shine)
      

  2.   

    to shine333(shine) :
        任务已经完成,真是十分感谢。
        但我还有一个问题:System.currentTimeMillis()的作用是什么啊?
      

  3.   

    Returns the current time in milliseconds.
      

  4.   

    System.currentTimeMillis()的作用是取出当前时间,是以某一个时间(1970年1月1日0点0分)为参照的毫秒数,类型为long。一下是sun的注释:
    /**
         * Returns the current time in milliseconds.  Note that
         * while the unit of time of the return value is a millisecond,
         * the granularity of the value depends on the underlying 
         * operating system and may be larger.  For example, many 
         * operating systems measure time in units of tens of 
         * milliseconds.
         *
         * <p> See the description of the class <code>Date</code> for 
         * a discussion of slight discrepancies that may arise between 
         * "computer time" and coordinated universal time (UTC). 
         *
         * @return  the difference, measured in milliseconds, between 
         *          the current time and midnight, January 1, 1970 UTC.
         * @see     java.util.Date
         */
        public static native long currentTimeMillis();