0
try{
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec("C:\\Windows\\explorer.exe");
    InputStream in = p.getInputStream();
    OutputStream out = p.getOutputStream();
    InputStream err = p.getErrorStream();
    p.destroy();
}catch(Exception e){
   //Handle Exception
}

因此,上面的代码可以根据需要打开资源管理器窗口或任何其他文件夹,但是如何关闭打开的窗口呢?我想过使用 Robot 类,但不确定如何去做。

4

1 回答 1

0

If you start the process from with in your Java application (ex. by calling Runtime.exec() or ProcessBuilder.start()) then you have a valid Process reference to it. In your case p

Process p = rt.exec("C:\\Windows\\explorer.exe");

you can invoke the destroy() method in Process class to kill that particular process.

But note it will kill the entire process which will include closing your explorer window.

于 2013-09-26T14:06:32.367 回答