在Java中捕获标准输出的内容 [英] Capturing contents of standard output in Java
本文介绍了在Java中捕获标准输出的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在调用一个在我的控制台/标准输出中打印一些字符串的函数。我需要捕获这个字符串。我不能修改正在进行打印的函数,也不能通过继承来改变运行时行为。我无法找到任何允许我这样做的预定义方法。
I am invoking a function that is printing some string in my console/standard output. I need to capture this string. I cannot modify the function that is doing the printing, nor change runtime behavior through inheritance. I am unable to find any pre-defined methods that will allow me to do this.
JVM是否存储打印内容的缓冲区?
Does the JVM store a buffer of printed contents?
有没有人知道有助于我的Java方法?
Does anyone know of a Java method that will aid me?
推荐答案
你可以暂时取代系统.err或System.out,其中包含一个写入字符串缓冲区的流。
You could temporarily replace System.err or System.out with a stream that writes to string buffer.
这篇关于在Java中捕获标准输出的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文