简体   繁体   中英

Java system.out.println console

I have code that uses system.out.println to print out an array of string objects. 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. 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?

Remove all the System.out.println() calls and replace them with a call to a logger (for example, 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.

Run your program like this:

java Program > /dev/null

On Windows, you can do this instead.

java Program >NUL

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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