try {
...
...
}catch(Exception e) {
e.printStackTrace();
}
请问如何将e.printStackTrace()显示的信息保存到一个指定的文档里?谢谢
...
...
}catch(Exception e) {
e.printStackTrace();
}
请问如何将e.printStackTrace()显示的信息保存到一个指定的文档里?谢谢
解决方案 »
- java 怎么样调用delphi服务器?像http:xxxxxx/xxx/xx?ss=ss&xx=as
- 一直报错:Fatal exception occurred,program will exit··为什么?怎么解决?
- JLabel中嵌入HTML时"align=left"失效?
- 序列化与反序列化
- 请问这个this是什么意思
- 请问大家 程序员可不可以自己编软件卖
- 急,求教关于在计算器中加入括号的算法
- 请各位高手帮忙,只是举手之劳,谢谢!!!
- 有谁知道IIOException中的一个Sample size must be <= 8 的异常问题!!!!!!!
- java applet程序中怎样实现图片的连续显示啊!!!
- eclipse提示问题
- window.open为什么在IE7中不好用呢,提示新窗口为空或不是对象,但在IE6中就没问题
我现在是在APPLICATION里出抛出的,那怎么才使用log4j这个呢?
try {
int i = 1/0;
} catch (Exception e) {
try {
new PrintWriter(new BufferedWriter(new FileWriter("c:/exception.txt",true)),true).println(e.toString());
} catch (IOException e1) {
e1.printStackTrace();
}
}
System.setErr(myStream); //重定向到myStream这样可以把所有的错误信息都输出到文件。
稍微改一下就好了
try {
int i = 1 / 0;
} catch (final Exception e) {
try {
new PrintWriter(new BufferedWriter(new FileWriter(
"c:/exception.txt", true)), true).println(new Object() {
public String toString() {
StringWriter stringWriter = new StringWriter();
PrintWriter writer = new PrintWriter(stringWriter);
e.printStackTrace(writer);
StringBuffer buffer = stringWriter.getBuffer();
return buffer.toString();
}
});
} catch (IOException e1) {
e1.printStackTrace();
}
}
也可以这样 e.printStackTrace(new FileOutputStream("文件名"));