读写文件的问题(100分。很急!!三天内揭贴)

sunny32 2003-02-27 09:36:29
把当前日期按一定格式写到文件中,并能从文件中读出来。(用到ObjectInputStream和ObjectOutputStream类)最好写出具体代码。。
谢谢!!
...全文
95 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
MagicJohn 2003-02-28
  • 打赏
  • 举报
回复
兄弟,这不是好办法。
自己做,自己想,对你又好处。
iceshape1 2003-02-28
  • 打赏
  • 举报
回复
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();
baitianhai 2003-02-28
  • 打赏
  • 举报
回复
Returns the current time in milliseconds.
lotofu 2003-02-28
  • 打赏
  • 举报
回复
抄就抄吧,还问什么呢?!!
真是的。。。
sunny32 2003-02-28
  • 打赏
  • 举报
回复
to shine333(shine) :
任务已经完成,真是十分感谢。
但我还有一个问题:System.currentTimeMillis()的作用是什么啊?
sunny32 2003-02-28
  • 打赏
  • 举报
回复
抄作业啊?

是啊,

谢谢 : shine333(shine)
mercury1231 2003-02-28
  • 打赏
  • 举报
回复
抄作业啊?
shine333 2003-02-27
  • 打赏
  • 举报
回复
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){}
}
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧