What is runtime.getruntime (). exec ("domain equivalent for cls") for Windows 7

I want to clear the screen in my Java application, after reading many questions and searching on Google, I found the code below

runtime.getruntime().exec("cls")

or

Runtime.getRuntime().exec("cmd /c cls");

but the code above does not work in Windows 7. I know that the "cls" script is a domain, does anyone know what text I should use in Windows 7. It will be really useful, thanks in advance.

+5
source share
2 answers

, . newline ANSI. Windows, JNA, , . . /// . , JNA. JNA, .

//------------------------------------------
// Java2Win.class
//------------------------------------------
public interface Java2Win extends Library {
    Java2Win java2Win = (Java2Win)Native.loadLibrary("Java2Win64",Java2Win.class);
    void cls();
}
//------------------------------------------

//------------------------------------------
// Java2Win.c (Java2Win.dll & Java2Win64.dll)
//------------------------------------------
JNIEXPORT void cls() {
   system("cls");
}
//------------------------------------------

//------------------------------------------
// Test
//------------------------------------------
public static void main(final String args[]) throws Exception {
    final File file = new File("rootToDLL", "Java2Win64.dll");
    LibraryLoader.loadLibrary(file);
    System.out.println("-----some output");
    System.out.println("-----some output");
    System.out.println("-----some output");
    Thread.sleep(2000);
    Java2Win.java2Win.cls();
    System.out.println("-----cleared");
}
//------------------------------------------
+1

cls (- cmd.exe , ),

cmd /c cls

Windows 7, .

+2

All Articles