【发布时间】:2014-01-05 19:59:25
【问题描述】:
'logger.info(message);'我的代码中的行创建了这个输出:
2013 年 12 月 17 日下午 12:54:50 温室.GreenhouseControls$ControllerException
我想使用 PrintWriter 将该行打印到文本文件中。这是我到目前为止所拥有的:
public ControllerException(String message, int errorcode) {
super(message);
this.errorcode=errorcode;
Logger logger = Logger.getLogger(ControllerException.class.getName());
logger.info(message);
String fileName = "error.log";
try {
PrintWriter outputStream = new PrintWriter(fileName);
outputStream.println("Time: " + ????); // Not sure what to put here..
outputStream.println("Reason: " + message);
outputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
我可以在打印行语句中包含什么来代替问号来实现这一点?
【问题讨论】:
-
你想完成什么?
outputStream.println("Reason: " + message);行应该将Dec 17, 2013 12:54:50 PM greenhouse.GreenhouseControls$ControllerException打印到您的文件中,这不会发生吗?你想为原因和时间部分显示什么?? -
@Ergin 我想我不需要两个打印语句。我可以在同一行打印“时间”和“原因”。我根本无法获得打印到文件的日期/时间。所以,我希望它在文件中打印 2013 年 12 月 17 日 12:54:50 PM温室.GreenhouseControls$ControllerException。