package 日志类;
import java.io.*;
public class 简单日志记录 {
private static void main(String[] args) {
print("e:/eee.txt","ddd");
}
/**
* 写入日志 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;
}
}
private static String getDate() {
return new java.util.Date().toString();
}
}
简单的日志记录
最新推荐文章于 2024-10-18 18:38:08 发布