简体   繁体   English

如何将控制台输出从System.out写入文件

[英]How to write console output from System.out to a file

I have a device that I am connected to over SSH via Java that listens to console inputs and prints out values via System.out (this part of the set-up I cannot change). 我有一台通过Java通过SSH连接到的设备,该设备侦听控制台输入并通过System.out打印出值(这部分设置我无法更改)。

I need to retrieve the plaintext output of the device and store it in a file. 我需要检索设备的纯文本输出并将其存储在文件中。 The data from the device is simple text sent to the System.out via SSH. 来自设备的数据是通过SSH发送到System.out的简单文本。 Is there any way to get that data and save it to a file as it comes in? 有什么方法可以获取数据并将其保存到文件中吗? I cannot change the output stream due to the constraints of the device. 由于设备的限制,我无法更改输出流。

我能够解决此问题的方法是,在与设备建立连接之前,将System.out PrintStream更改为FileOutputStream,然后解析此流生成的日志以获取所需的数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM