/**
* 写入日志
* 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);
System.out.println(getDate()+":"+code);
pw.println(getDate()+":"+code);
pw.close();
bw.close();
fw.close();
return true;
} catch (IOException e) {
return false;
}
}
Java_写入日志
最新推荐文章于 2021-03-04 09:11:29 发布
本文介绍了一种在Java中记录日志的方法。该方法通过创建FileWriter和BufferedWriter对象将指定的内容写入到指定路径的日志文件中,并确保每次写入时都在原有内容的基础上追加。如果操作过程中出现IOException,则返回失败。
563

被折叠的 条评论
为什么被折叠?



