import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
/**
* 文件写入
* @author Administrator
*
*/
public class TestReadAndWrite {
public static void writerText(String path, String content) {
File dirFile = new File(path);
if (!dirFile.exists()) {//判断目录是否存在,不存在创建
dirFile.mkdir();
}
try {
//new FileWriter(path + "config.log", true) 设置true 在不覆盖以前文件的基础上继续写
BufferedWriter writer = new BufferedWriter(new FileWriter(path + "config.log", true));
writer.write(content+"\r\n");//写入文件
writer.flush();//清空缓冲区数据
writer.close();//关闭读写流
System.out.println("写入成功");
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
writerText("D:/", "2014-07-14 23:43:00 服务器IP:192.123.123.243 日志信息:后台登录验证码出现错误,错误代码500");
}
}
posted on 2015-02-03 12:00
sevennight 阅读(88)
评论(0) 编辑 收藏