请问此程序错在哪里?怎么改?

hlj3171 2007-05-12 06:28:03
import java.io.*;
import java.util.*;
class Logger{
public void Log() throws Exception{
PrintStream logps;
GregorianCalendar now;
logps=new PrintStream(new FileOutputStream("log"));
now=new GregorianCalendar();
logps.println(now.getTime());
}
public void logWithTZ() throws Exception
{PrintStream logps;
GregorianCalendar now;
logps=new PrintStream(new FileOutputStream("log"));
now=new GregorianCalendar();
logps.print(now.getTimeZone().getDisplayName()+" ");
logps.println(now.getTime());
}
}
...全文
233 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tyztyz1006 2007-05-13
  • 打赏
  • 举报
回复
没有main函数不 行的吧!这个错误最明显了

tanlingyun 2007-05-12
  • 打赏
  • 举报
回复
main方法没有啊
public static void main(String[] args)throws Exception
{
Logger logg = new Logger();
logg.Log();
logg.logWithTZ();
}
还有这个语句logps=new PrintStream(new FileOutputStream("log"));
log是写如数据的文件,应该加个后缀吧,log.txt

完整的程序如下:
import java.io.*;
import java.util.*;
class Logger{
public void Log() throws Exception{
PrintStream logps;
GregorianCalendar now;
logps=new PrintStream(new FileOutputStream("log.txt"));
now=new GregorianCalendar();
logps.println(now.getTime());
}
public void logWithTZ() throws Exception
{PrintStream logps;
GregorianCalendar now;
logps=new PrintStream(new FileOutputStream("log2.txt"));
now=new GregorianCalendar();
logps.print(now.getTimeZone().getDisplayName()+" ");
logps.println(now.getTime());
}
public static void main(String[] args)throws Exception
{
Logger logg = new Logger();
logg.Log();
logg.logWithTZ();
}
}
运行完后在当前目录下有log.txt和log2.txt
yuanlv 2007-05-12
  • 打赏
  • 举报
回复
类名Logger 和构造函数的名称不一致啊。
约翰羊 2007-05-12
  • 打赏
  • 举报
回复
报什么错误?

62,614

社区成员

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

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