/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package classes;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;
import javax.swing.JOptionPane;
/**
*
* @author Administrator
*/
public class AddLog {
public static void addlog(String error)//將錯誤信息寫入日誌
{
FileWriter fw=null;
BufferedWriter bw=null;
File logFile=null;
String containt=(new Date()).toString()+"/t/t"+error;
try {
logFile = new File("datalog.zhoujian");
if (!logFile.exists()) {
logFile.createNewFile();//如果該日誌文件不存在,則新建一個
}
fw=new FileWriter(logFile,true);//以追加的模式操作文件
bw=new BufferedWriter(fw);
bw.newLine();
bw.newLine();
bw.write(containt);
bw.close();
fw.close();
}
catch (IOException ex) {
JOptionPane.showMessageDialog(null,"寫入日誌文件出錯!","嚴重警告",JOptionPane.ERROR_MESSAGE);
}finally{
}
}
}