public static void main(String[] args) {
try {
throw new Exception("error");
} catch (Exception e) {
//字符串和输出流的桥梁StringWriter
StringWriter sw = new StringWriter();
//创建输出流并包装writer对象
PrintWriter pw = new PrintWriter(sw);
//参数传递
e.printStackTrace(pw);
//打印异常的详细信息
System.out.println(sw.toString());
}
}
唉,如此问题难以回答,一个小例子,改掉catch块里的代码成你想知道的输出类。就能打印出来了 |