我们如何将Java程序控制台输出重定向到多个文件? [英] How can we redirect a Java program console output to multiple files?

查看:124
本文介绍了我们如何将Java程序控制台输出重定向到多个文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将eclipse控制台输出重定向到文件?我可以:

How can we redirect the eclipse console output to a file? I can:


  1. 运行配置 - > Commons - > 选择一个文件

  2. 使用 System.setOut(PrintStream) / code>和 System.setErr(PrintStream)

  1. Run Configuration->Commons->Select a file.
  2. Use System.setOut(PrintStream) and System.setErr(PrintStream).

1)的问题是我需要将控制台输出记录到不同的文件,而不是一个文件。

The problem with 1) is that I need to record console output to different files instead of one file.

2)的问题是它只存储由 System.out.println()生成的控制台输出,或堆栈跟踪抛出异常。它不捕获其他类型的输出,例如log4j警告等

The problem with 2) is that it only stores console output generated by System.out.println() or stacktrace of an exception thrown. It does not capture other kind of outputs e.g. log4j warnings etc.

我们如何以控制台方式将控制台输出重定向到不同的文件?

How can we redirect console output to different files programmatically?

推荐答案

转到运行,然后选择运行配置 - > 常用,并在标准输入和输出中可以选择一个文件。

Go to run as and choose Run Configurations -> Common and in the Standard Input and Output you can choose a File also.

这篇关于我们如何将Java程序控制台输出重定向到多个文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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