public static void Log(String conent) {
String file="D://home/wwwroot/abcd/logs/log_"+DateUtil.getDateFormat(new Date(),"yyyy_MM_dd")+".txt";
String start="\n\n---------------------------"+DateUtil.getDateFormat(new Date(),"yyyy-MM-dd HH:mm:ss")+"--------------------------------------------------\n\n";
String end="\n\n--------------------------------------------------------------------------------------------------\n\n";
conent=start+conent+end;
BufferedWriter out = null;
try {
File txtFile=new File(file);
if(!txtFile.exists()){
txtFile.createNewFile();
}
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, true)));
out.write(conent);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if(out != null){
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Java做txt日志记录
最新推荐文章于 2024-07-15 15:48:36 发布