国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Java > 正文

java捕獲異常信息存入txt文件示例

2019-11-26 15:32:56
字體:
來源:轉載
供稿:網友

捕獲程序中出現的異常 可用于后期維護的必要性!做簡單的測試 !

復制代碼 代碼如下:

package helpEntity;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Log {
 private File file = null;

 public File getFile() {
  return file;
 }

 public void setFile(File file) {
  this.file = file;
 }

 public void saveLog(Exception e, String youName) {
  try {
   String nowPath = null;
   nowPath = System.getProperty("user.dir");
   String tempPath = null;
   this.file = new File(nowPath);
   tempPath = this.file.getParent();
   if (tempPath == null) {
    this.file = new File(nowPath);
   }
   this.file = new File(tempPath + "" + File.separator + "log.txt");
   PrintWriter writer = null;
   FileWriter fileWrite = new FileWriter(file, true);
   writer = new PrintWriter(fileWrite);
   writer.append(System.getProperty("line.separator")
     + new SimpleDateFormat("yyyy-MM-dd:HH:mm:ss")
       .format(new Date()) + "__" + youName);
   writer.append(System.getProperty("line.separator"));
   writer.append("      *************************" + e.toString()
     + "*************************");
   writer.append(System.getProperty("line.separator"));
   e.printStackTrace(writer);
   writer.flush();
   writer.close();
  } catch (Exception e2) {
   e2.printStackTrace();
  }
 }
}

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 通州市| 囊谦县| 金门县| 塔河县| 眉山市| 蓝田县| 湖南省| 黄梅县| 鄢陵县| 彰化县| 宁阳县| 北碚区| 麦盖提县| 颍上县| 拉萨市| 延津县| 冕宁县| 云林县| 南安市| 邯郸县| 且末县| 丹江口市| 呼玛县| 武安市| 延津县| 肥城市| 黔江区| 通渭县| 斗六市| 红桥区| 陕西省| 德格县| 外汇| 裕民县| 贵南县| 洪雅县| 鸡泽县| 芜湖县| 紫金县| 临洮县| 阆中市|