读书人

简略的记录日志的方法(Log.java)

发布时间: 2012-10-29 10:03:53 作者: rapoo

简单的记录日志的方法(Log.java)
package com.ly.util;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Log {

public static void logt(String fileName , String message){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
String ss= new String();
String sb= new String();
ss=dateFormat.format(new Date())+"------"+message+"\n";
sb="log_"+fileName+".txt";
File f= new File(sb);
FileWriter fw = null;
try {
fw = new FileWriter(f,true);
fw.write(ss);
fw.flush();
fw.close();
} catch (IOException e) {
e.printStackTrace();
} finally{
if(fw!=null){
try {
fw.close();
} catch (IOException e) {
e.printStackTrace();
}

}

}
}
}

读书人网 >编程

热点推荐