Java中的多个命令提示符/控制台? [英] Multiple Command Prompts / Consoles in Java?
问题描述
也许是一个尴尬的问题,但我想知道是否有可能运行一个Java控制台应用程序,该应用程序以某种方式链接到多个命令提示符.
Maybe an awkward question but I am wondering whether it is possible to have one Java console application running which is linked somehow to more than one command promt.
我欣赏的是一个Java应用程序,它提供一个控制台来读取控制台输入,一个控制台来提供类型A的控制台输出,一个控制台来提供类型B的输出,等等.
What I admire is to have a Java application which provides one console for reading console input, one for providing console output of type A, one for providing output of type B and so forth.
对此有任何想法或评论吗?
Any ideas or comments on that?
我正在考虑类似..
System1.out.println(输出A");
System2.out.println(输出B");
我的特殊问题如下:
我必须通过控制台向用户提供大量输出,为了使其更具可读性并提供更多的结构概述,我想使用更多的控制台.
I have to provide lots of output to the user via the console and in order to make it more readable and to provide a more structures overview I would like to use more consoles.
推荐答案
不可能像您一样使用 System1.out.println("..."); 表明的;但是,系统可以使用"setOut(PrintStream out)"方法:
it is not possible to use System1.out.println("..."); like you've indicated; however, System has a "setOut(PrintStream out)" method that you could use:
try {
PrintStream psA = new PrintStream("My_Output_A.log");
PrintStream psB = new PrintStream("My_Output_B.log");
System.setOut(psA);
System.out.println("Message for A");
System.setOut(psB);
System.out.println("Message for B");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
上面的代码将消息打印到2个单独的文件中.
我认为这是您对应用程序所期望的.
The above code prints the messages to 2 separate files.
I think this is what you desired for your application.
这篇关于Java中的多个命令提示符/控制台?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!