Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Run your program like this:

java Program > /dev/null

On Windows, you can do this instead.

java Program >NUL
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top