Java-写入日志到指定的文件

时间:2025-03-22 19:07:32
import ;
import ;
import ;
import ;
import ;
/**
* 写入日志
* filePath 日志文件的路径
* code 要写入日志文件的内容
*/
public class PrintToFile {
	/**
	 * 写入日志 filePath 日志文件的路径 code 要写入日志文件的内容
	 */
	public static  boolean print(String filePath, String code) {
		try {
			File tofile = new File(filePath);
			FileWriter fw = new FileWriter(tofile, true);
			BufferedWriter bw = new BufferedWriter(fw);
			PrintWriter pw = new PrintWriter(bw);
			GetNowDate getnowdata=new GetNowDate();//Java-取得服务器当前的各种具体时间
			(()+":"+code);
			(()+":"+code);
			();
			();
			();
			return true;
		} catch (IOException e) {
			return false;
		}
	}
	public static void main(String[] args){
		print("c:/","hahahhhah");
	}
}