public class OutFileUtil {
/**
* 输出当前日志文件
* @param print
* @throws IOException
*/
public static void outFile(String print) throws IOException {
SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
String date=sdf.format(new Date());
File f=new File("../logs/SynMessage_log_"+date+".txt");
if(!f.exists()){
f.createNewFile();
}
FileOutputStream fileOutputStream = new FileOutputStream(f,true);
PrintStream printStream = new PrintStream(fileOutputStream);
printStream.append(getCurrentDate()+print);
}
public static String getCurrentDate(){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");//设置日期格式
return "\r\n"+"["+sdf.format(new Date())+"]";// new Date()为获取当前系统时间
}
}
java手动书写日志文件
最新推荐文章于 2024-07-23 22:58:04 发布