You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 lines
801 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package com.util;
/**
* 日志
*/
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
public class Log {
public void addLog(String str){
try {
File file=new File("c://log.txt");
FileWriter fw=new FileWriter(file,true);
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw = new PrintWriter(bw);
pw.write(str);
bw.newLine();//断行
bw.flush();//将数据更新至文件
pw.close();
fw.close();//关闭文件流
} catch (FileNotFoundException e) {
System.out.println("警告:日志文件没找到!!!!");
e.printStackTrace();
} catch (IOException e) {
System.out.println("警告日志文件IO错误");
e.printStackTrace();
}
}
}