方法一:

public static String getStackTrace(Throwable t) {
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    try {
        t.printStackTrace(pw);
        return sw.toString();
    } finally {
        pw.close();
    }
}

方法二:

org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace(e);

 

posted on 2017-01-16 10:44  玄同太子  阅读(12463)  评论(0编辑  收藏  举报