0

When trying to use the ANSI escape codes, it would not work. I would assume this is because JCreator does not support these escape codes. Is there any other way to print out color when using System.out.println? The ANSI codes I am using is below along with what I am trying to print as a trial. The code is inside a class and it is running properly.

final String ANSI_RESET = "\u001B[0m";
final String ANSI_BLACK = "\u001B[30m";
final String ANSI_RED = "\u001B[31m";
final String ANSI_GREEN = "\u001B[32m";
final String ANSI_YELLOW = "\u001B[33m";
final String ANSI_BLUE = "\u001B[34m";
final String ANSI_PURPLE = "\u001B[35m";
final String ANSI_CYAN = "\u001B[36m";
final String ANSI_WHITE = "\u001B[37m";
System.out.println(ANSI_RED + "This text is red!" + ANSI_RESET);
Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
jmm8398
  • 11
  • 2

1 Answers1

0

There is no concept of color with System.out. Its an abstraction that is used to output text to any kind of target, be it the console of an IDE, a file or a NULL target that discards the output.

ANSI codes are understood only by an ANSI compatible console, for example the windows command line prompt. So if you run your code from cmd (without redirecting the output), you will see the codes take effect. In your IDE's console they wont.

Durandal
  • 19,919
  • 4
  • 36
  • 70