How to print color in console using System.out.println?

后端 未结 13 2498
灰色年华
灰色年华 2020-11-22 05:22

How can I print color in console? I want to show data in colors when the processor sends data and in different colors when it receives data.

13条回答
  •  一个人的身影
    2020-11-22 06:14

    A fairly portable way of doing it is with the raw escape sequences. See http://en.wikipedia.org/wiki/ANSI_escape_code

    [edited for user9999999 on 2017-02-20]

    Java doesn't "handle the codes", that's true, but Java outputs what you told it to output. it's not Java's fault that the Windows console treats ESC (chr(27)) as just another glyph (←).

提交回复
热议问题