0

I am migrating code from C # to JAVA in Netbeans for class work and I have a little problem with this; in C# I use Console.Clear to clean command prompt and make it look readable and very interactive, but in Netbeans it doesn't have a function to clean its output, what it does have is the "Clean" with the shortcut "Control + L", I found that the "Robot" class could be used to "automate" it in a certain sense but I don't know why but the normal sequence like being canceled or crashed, nothing appears after applying a "System.out.println".

Then I would like to know if it can be done in another way (except run it by cmd using the command "java -jar path")

1 Answers1

0

1 - First solution, sadly, on Windows, there is no clean way of doing so. You'll need to use a load of System.out.println(""); in order to do so.

2 - The second solution, on Unix systems, there is an ANSI Escape Sequence that accomplishes that, and it's \033[2J once printed this will clear the console.

3 - The third solution. Install a plugin for NetBeans to make the console support ANSI sequences which would allow you to use colors and the \033[2J method.

4 - Finally, there's a Java library for that purpose that detects the current console/terminal and allows you to interact with it like you would with any other ones. Its called jcurses

Jessy Guirado
  • 220
  • 1
  • 7