如何在 java 中维护日志文件
How to mainain log file in java
我想在同一个文件中每次执行后存储(追加)我的 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
}
我想在同一个文件中每次执行后存储(追加)我的 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
}