How to Print Colored Text Console Output in Java

While programming in Java sometimes you may need to print the output of the program in the console to testing and debugging the program. While program throws many exceptions and prints tens of lines in the console, you may find it difficult to find the actual exception message.

In this case, it is good practice to change the color of the particular exception message so that we can easily debug the program and it will make our work easier.

There is another need to modify the output color of text while you are writing the command line application. It is a good Idea to change the color of the particular output line to highlight the main point of the output.

I find this trick useful while programming such type of command line tool and the debugging the web and desktop application.

You can also use this tricks to change the console output color using system.out.print() function in Java.

However this DOS / Window doesn’t support the ANSI colored character so that you won’t be able to run this program correctly in the Windows Command Prompt. You can use the console of the IDE like Eclipse, NetBeans etc and the any Linux distro terminal.

Change Output Text Color In Java

Source Code

OutPut

change-console-text-color-java-codepuran

1 reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *