Код: Выделить всё
System.out.print("\033[H\033[2J");
System.out.flush();
Однако, когда я пытаюсь запустить его с помощью Dr. Java, это не сработает. Я не думаю, что Dr. Java поддерживает escape-коды ANSI. Я также почти на 100% уверен, что Dr. Java не основан на UNIX.
Мне также не удалось заставить Dr. Java правильно выполнить эту опцию:
Код: Выделить всё
import java.io.IOException;
public class CLS {
public static void main(String... arg) throws IOException, InterruptedException {
new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor();
}
}
Код: Выделить всё
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();
}
}
}
Код: Выделить всё
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
Подробнее здесь: https://stackoverflow.com/questions/798 ... ole-method
Мобильная версия