I can write a method that will clear the console:
System.out.print("\033[H\033[2J");
System.out.flush();
and this method works great with online IDEs like Juicemind and Repl.it. I think it's because they are UNIX based.
However, when I try to run it using Dr. Java, it won't work. I don't think Dr. Java supports ANSI escape codes. I am also almost 100% certain that Dr. Java is not UNIX Based.
I also could not get Dr. Java to correctly execute this option:
import java.io.IOException;
public class CLS {
public static void main(String... arg) throws IOException, InterruptedException {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
}
When I try this one:
import java.io.IOException;
public class CLS {
public static void main(String[] arg) throws IOException, InterruptedException {
clearConsole();
}
public static void clearConsole() throws Exception {
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("windows")) {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
} else {
new ProcessBuilder("clear").inheritIO().start().waitFor();
}
}
}
I get a compiler error that I don't know how to fix:
2 errors found:
[line: 12]
Error: The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from required .class files
[line: 12]
Error: The method contains(java.lang.CharSequence) from the type java.lang.String refers to the missing type java.lang.CharSequence
Does anyone have any experience with a way to clear the console for a lightweight pedagogical environment like Dr. Java? Is there something about Dr. Java that prevents one from writing a method that will clear the console?