如何在java中维护日志文件
我想在每次执行后将java代码的输出存储(追加)到同一个文件中。例如包括SOP语句、执行时间、执行的文件数等。尝试以下方法:如何在java中维护日志文件,java,logfile,Java,Logfile,我想在每次执行后将java代码的输出存储(追加)到同一个文件中。例如包括SOP语句、执行时间、执行的文件数等。尝试以下方法: try(FileWriter fw = new FileWriter("outfilename", true); BufferedWriter bw = new BufferedWriter(fw); PrintWriter out = new PrintWriter(bw)) { out.println("the text"); // appen
try(FileWriter fw = new FileWriter("outfilename", true);
BufferedWriter bw = new BufferedWriter(fw);
PrintWriter out = new PrintWriter(bw))
{
out.println("the text"); // appends text
//more code
out.println("more text"); // appends text
//more code, append more text etc.
} catch (IOException e) {
//exception handling left as an exercise for the reader
}
您需要有关附加到文件或获取执行时间和其他详细信息的帮助,请澄清。检查此处:我想将上述所有内容存储在单个文件中。就像每次执行程序一样,所有细节都应该存储在同一个文件中。@NikhilTalaviya感谢您的链接