【问题标题】:How to clear the screen in java in cmd [duplicate]如何在cmd中清除java中的屏幕[重复]
【发布时间】:2013-10-04 04:49:00
【问题描述】:

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

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

请输入代码:

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");
    }
}

【问题讨论】:

标签: java


【解决方案1】:

这可以工作

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

【讨论】:

  • Console类没有明确事件请查看
猜你喜欢
  • 2015-08-17
  • 1970-01-01
  • 1970-01-01
  • 2011-06-16
  • 2011-04-08
  • 2023-04-04
  • 2013-08-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多