I saw this topic: Java: Clear the console but does not work in Windows for me.
I have this code:
import java.io.IOException;
public class hola {
public static void limpiar_pantalla() throws IOException {
String os = System.getProperty("os.name");
if (os.contains("Windows"))
{
System.out.println("Win 1");System.out.println("Win 1");
Runtime.getRuntime().exec("cls");
//for (int i = 0; i < 50; ++i) System.out.println();
System.out.println("Win 2");
}
else
{
System.out.println("Linux 1");
Runtime.getRuntime().exec("clear");
//for (int i = 0; i < 50; ++i) System.out.println();
System.out.println("Linux 2");
}
}
public static void main(String[] args) throws IOException {
hola.limpiar_pantalla();
}
}
This is the Linux output:
Linux 1
Linux 2
and the windows output:
F:\bin>java -jar sacar_systema_java.jar Win 1 Exception in thread "main" java.io.IOException: Cannot run program "cls": Create
Process error=2, El sistema no puede hallar el archivo especificado
at java.lang.ProcessBuilder.start(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at java.lang.Runtime.exec(Unknown Source)
at hola.limpiar_pantalla(hola.java:10)
at hola.main(hola.java:24)
Caused by: java.io.IOException: CreateProcess error=2, El sistema no puede hallar el archivo especificado
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
... 6 more
F:\bin>
basicly cls: command not found
I don' know why does not work.
Can anybody help?