首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

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

2012-10-29 
简单的记录日志的方法(Log.java)package com.ly.utilimport java.io.Fileimport java.io.FileWriterimp

简单的记录日志的方法(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();
}
               
        }
       
        } 
    }
}

热点排行