简体   繁体   English

Java system.out.println控制台

[英]Java system.out.println console

I have code that uses system.out.println to print out an array of string objects. 我有使用system.out.println打印出字符串对象数组的代码。 These string objects are then saved to a text file. 然后将这些字符串对象保存到文本文件中。 Everything works great with the program but when the program is compiling the system.out.println prints all of the strings to the console. 一切都适合该程序,但是当程序正在编译system.out.println时,会将所有字符串打印到控制台。 Is there anyway I can make it so that the user does not see what the system.out.println produces when I save a file? 无论如何,我可以做到这一点,以便用户在保存文件时看不到system.out.println产生什么?

Remove all the System.out.println() calls and replace them with a call to a logger (for example, log4J ). 删除所有System.out.println()调用,并将其替换为对记录器的调用(例如, log4J )。 Then, you can globally turn on/off logging in your application or set different logging levels using configuration files. 然后,您可以全局打开/关闭应用程序中的日志记录,或使用配置文件设置不同的日志记录级别。 In general, it's a bad idea to leave System.out.println() calls in production code, that's what loggers are for. 通常,将System.out.println()调用留在生产代码中是个坏主意,这就是记录器的作用。

Run your program like this: 像这样运行程序:

java Program > /dev/null

On Windows, you can do this instead. 在Windows上,您可以改为执行此操作。

java Program >NUL

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

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