我想在java代码中记录。而且,整个过程需要几个小时才能完成。但是我的代码在执行结束时记录了所有日志,因为缓冲区在最后关闭。
有什么方法可以附加到日志文件中吗?
请查看我的代码,并提出一些必要的更改。提前致谢。
我的代码,
public class test {
public static void func(String url1, String url2, BufferedWriter bw) throws InterruptedException, IOException {
long loading_time = 10878;
long parsing_time = 120;
long processing_time = 329;
Thread.sleep(100000000); // Here is some process that performs recursively
bw.write( url1 + "\n" + url2 + "\n"+ ((double)loading_time)/((double)1000)+ " seconds " + ((double)parsing_time)/((double)1000) + " seconds " + ((double)processing_time)/((double)1000) + " seconds\n\n\n\n" );
}
public static void main(String[] args) throws IOException, InterruptedException{
try {
FileWriter fw = new FileWriter("C:\\Users\\jhamb\\Desktop\\log.txt");
BufferedWriter bw = new BufferedWriter(fw);
for(int i = 0; i < 5; i++) { func("hitesh", "jhamb", bw); }
bw.close();
} catch (Exception e) {
System.out.println("Sorry some problem");
}
}
}