码迷,mamicode.com
首页 > 编程语言 > 详细

java中将异常写入到txt文本

时间:2015-11-25 10:12:02      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:

 

代码如下:

try{
	******
} catch (Exception ex) {
				  try {
					  File file = new File("e:/log.txt");

					  PrintWriter writer = null;
					  FileWriter fileWrite = new FileWriter(String.valueOf(file), true);
					  writer = new PrintWriter(fileWrite);
					  writer.append(System.getProperty("line.separator") + new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss").format(new Date()));
					  writer.append(System.getProperty("line.separator"));
					  writer.append("*************************" + ex.toString() + "*************************");
					  writer.append(System.getProperty("line.separator"));
					  ex.printStackTrace(writer);
					  writer.flush();
					  writer.close();
				  } catch (IOException e) {
					  e.printStackTrace();
				  }
}

java中将异常写入到txt文本

标签:

原文地址:http://www.cnblogs.com/sjshare/p/4993703.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!