2013-10-04 21 views
-1

如何清除Java中的屏幕 loke clrscr()命令c。如何在cmd中清除java中的屏幕

我使用命令提示符来运行程序。

请把代码:

class Demo 
{ 
    public static void main(String[] s) 
    { 
     //clear scrren hear 
     System.out.println("Hello World"); 
    } 
} 

还可以使用Runtime类,但多数民众赞成不行请给予同样的代码来执行此操作。

也是用这个代码,但不工作:

 import java.io.*; 
     class demo 
{ 
    public static void main(String[] s) 
    { 
     try 
{ 
    String os = System.getProperty("os.name"); 

    if (os.contains("Windows")) 
    { 
     Runtime.getRuntime().exec("cls"); 
    } 
    else 
    { 
     Runtime.getRuntime().exec("clear"); 
    } 
} 
catch (Exception exception) 
{ 
} 
     //clear scrren hear 
     System.out.println("Hello World"); 
    } 
} 
+0

这里是一个很好的解决方案:http://stackoverflow.com/questions/1682212/clear-screen-选项在java – Niki

+0

为什么你不谷歌它... –

+0

因为所有的代码不起作用 –

回答

0

这可能是工作

Console console = System.console();   
console.clear(); 
+0

控制台类没有明确的事件,请检查它 –