请教java清屏

GemScorpio 2005-03-31 11:52:53
import java.io.*;
public class cls {
public static void main(String[] args) {
//clear the screen(for Windows System)
try
{
Process process = Runtime.getRuntime().exec ("cls");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
LineNumberReader in = new LineNumberReader (ir);
String line;
while ((line = in.readLine ()) != null)
System.out.println(line);
}
catch (Exception e) {
System.err.println ("IOException " + e.getMessage());
}
System.out.println("Hello");
System.out.println("How are you!");
}
}
我在win下运行为什么就会发生IOException
...全文
844 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
itjourney 2005-04-01
  • 打赏
  • 举报
回复
再试试这个Process process = Runtime.getRuntime().exec("cmd.exe /c cls");
DanielYWoo 2005-04-01
  • 打赏
  • 举报
回复
说实话,不太懂你的意思,假如你开了三个dos窗口
你要清哪个屏?
oyljerry 2005-03-31
  • 打赏
  • 举报
回复
要么直接找到cls命令,执行
logic_online 2005-03-31
  • 打赏
  • 举报
回复
哦,还有,忘了说了,你的程序实际上相当于在运行中输入CLS,由于CLS不是可运行的程序或批处理文件,所以你的调用是一定会产生IOException的.
logic_online 2005-03-31
  • 打赏
  • 举报
回复
不好意思,实在是不知道你说的实现清屏是什么意思?
但是Runtime.getRuntime.exec()方法调用的程序都是没有图形化用户界面的,只是作为Java虚拟机建立的一个后台线程在运行,即使使用CLS清屏,你也是看不到任何结果的.
oyljerry 2005-03-31
  • 打赏
  • 举报
回复
嗯,对于cls,需要通过cmd来执行
GemScorpio 2005-03-31
  • 打赏
  • 举报
回复
好像还是不行耶!用cmd.exe调用的仅仅是cmd.exe而已,没用清屏!
start cls也不行
DanielYWoo 2005-03-31
  • 打赏
  • 举报
回复
ipconfig.exe是外部命令,当然可以
cls是内部命令,必须要用cmd.exe cls或者start cls吧
itjourney 2005-03-31
  • 打赏
  • 举报
回复
对应行修改为如下:
Process process = Runtime.getRuntime().exec("cmd.exe cls");
^^^^^^^^^^^^^
GemScorpio 2005-03-31
  • 打赏
  • 举报
回复
但是我要实现清屏啊!怎么办?
jianghuxing 2005-03-31
  • 打赏
  • 举报
回复
import java.io.*;
public class Test4 {
public static void main(String[] args) {
//clear the screen(for Windows System)
try
{
Process process = Runtime.getRuntime().exec("ipconfig");
}
catch (Exception e) {
System.err.println ("IOException " + e.getMessage());
}
System.out.println("Hello");
System.out.println("How are you!");
}
}
这就和行,呵呵,
jianghuxing 2005-03-31
  • 打赏
  • 举报
回复
import java.io.*;
public class Test4 {
public static void main(String[] args) {
//clear the screen(for Windows System)
try
{
Process process = Runtime.getRuntime().exec("ipconfig");
InputStreamReader ir=new InputStreamReader(process.getInputStream());
LineNumberReader in = new LineNumberReader (ir);
String line;
while ((line = in.readLine ()) != null)
System.out.println(line);
}
catch (Exception e) {
System.err.println ("IOException " + e.getMessage());
}
System.out.println("Hello");
System.out.println("How are you!");
}
}

重新来一个就行,那个没有输出吧。
teddywtd 2005-03-31
  • 打赏
  • 举报
回复
沙发,呵呵,第一个哦

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧