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());
}
}
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());
}
}
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