Java 输出控制台错误消息到文件? [英] Java output console error message to file?

查看:19
本文介绍了Java 输出控制台错误消息到文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段简单的代码,可以将控制台文本输出到 Java 中的文本文件:

I have a simple piece of code that outputs console text to a text file in Java:

PrintStream out = new PrintStream(new FileOutputStream("test2_output.txt"));
System.setOut(out);

但是我要求这个文本文件包含在控制台中产生的错误消息,但它们不包括在内.

However I require this text file to contain the error messages that is produced in the console but they are not included.

我该怎么做?

推荐答案

添加:

System.setErr(out);

最后.

这篇关于Java 输出控制台错误消息到文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆