Take the 2-minute tour ×

I have serious problem. I have one program which works with Command prompt, and the program can write color messages into it. And it also saves the messages to text .log file. But when I read the log with my java program, it writes instand of yellow text this: [33;1m before text which should be yellow. I noticed that [37;22m is for dark green, [37;1m is for white etc. (Before this code is a small arrow, but I can't paste it anywhere.)

Does anyone know what this codes suppose to be and how to rewrite it to java.awt.Color.Color which I am able to use? Thanks.

share|improve this question
add comment

3 Answers

up vote 1 down vote accepted

Yes these are escape sequences used to signal to a terminal that you want to change the current color (this style is also used for telling the terminal to move the cursor as well.). What type of terminal is this for? AFAIK Yellow should be \033[1;33m, dark green should be \033[0;32m, and White should be \033[1;37m. To switch back to the previous color would be \033[0m.

As for converting them to Java Color, I don't believe there is a built in API call for that, however it should be pretty easy to write one yourself.

If you are writing for Linux/Bash here is a handy guide:

share|improve this answer
I just don't know what the numbers eg. in [37;22m mean, so I can't write some API for this... –  PerwinCZ Mar 6 '13 at 15:14
@PerwinCZ As you are reading the log file, each time you encounter one of those sequences, switch your output color to the corresponding java.awt.Color. If you don't want the colors then you can safely filter these out. The sequences are simply output to indicate to the terminal displaying the text that the color should be changed. By emulating this in your Java program you should get the proper effect. –  Freedom_Ben Mar 6 '13 at 15:18
OK and how could I filter these sequences out? It is too difficult for me too. Could you help? Thanks. –  PerwinCZ Mar 6 '13 at 15:22
@PerwinCZ To filter them out I would write a regular expression that matches them and call logString.replaceAll( colorSequenceRegEx, "" ); –  Freedom_Ben Mar 6 '13 at 15:39
@PerwinCZ the Wikipedia page about ANSI escape codes describes what the numbers mean. Scroll down on that page to "Colors". –  Jesper Mar 6 '13 at 15:44
add comment

These are probably ANSI escape codes.

share|improve this answer
add comment

These are ANSI terminal codes. I am afraid I can't help with the second part of your question.

share|improve this answer
add comment

Your Answer


