如何附加日志文件 [英] How to append the log file

查看:70
本文介绍了如何附加日志文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在每次执行时追加日志文件。

如何使用以下代码执行此操作...



我尝试过:



我正在使用此代码编写日志文件.....



I want to append the log file on each time of execution.
How to do this using fallowing code...

What I have tried:

I'm writing log file using this code.....

static String fileTempPath= System.getProperty("java.io.tmpdir");
	static Date ch=new java.sql.Date(System.currentTimeMillis());
	static File tempFile=new File(fileTempPath+"PurgeLog"+ch  +  ".log");
		static PrintWriter out;
    public static void main(String[] args)                             
    {
				out=new PrintWriter(tempFile);
				out.println("main started:")
			 out.println("heloooo:")
out.close();
			 
    }
	}

推荐答案

使用 FileWriter(Java Platform SE 7) [ ^ ]类和接受追加的构造函数参数:

Use the FileWriter (Java Platform SE 7 )[^] class and the constructor that accepts an append parameter:
FileWriter out = new FileWriter(fileTempPath+"PurgeLog"+ch + ".log", true);
out.write("main started:\n");
out.write("heloooo:\n");
out.close();


这篇关于如何附加日志文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆