Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在java中维护日志文件_Java_Logfile - Fatal编程技术网

如何在java中维护日志文件

如何在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

我想在每次执行后将java代码的输出存储(追加)到同一个文件中。例如包括SOP语句、执行时间、执行的文件数等。

尝试以下方法:

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感谢您的链接