问题描述
我有一个代码,使用jDesktop打开一个Windows资源管理器界面,当我点击按钮登录,它正常工作。
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){
// TODO在此处添加您的处理代码:
桌面桌面= Desktop.getDesktop();
文件dirToOpen;
try {
dirToOpen = new File(C:// as // 2010-0000-1);
desktop.open(dirToOpen);
} catch(IOException ex){
ex.getMessage();
} catch(IllegalArgumentException iae){
System.out.println(File Not Found);
}
}
那么现在,我的问题是当我点击按钮注销,jDesktop的windows资源管理器界面也应该是关闭的...我不知道要使用什么代码....
这不是那么简单,他们只有机会,如果你有参考有关的过程。这意味着你需要更多地控制进程...这也意味着它只能在Windows上工作...
我使用以下代码在Windows资源管理器中显示指定的文件...
String path = file.getCanonicalPath();
ProcessBuilder pb = new ProcessBuilder(explorer.exe,/ select,+ path);
pb.redirectError();
进程proc = pb.start();
一旦您有权访问流程
您可以尝试使用 Process#destory
来尝试并终止该过程。
启动过程应该从单独的线程,所以你不会让自己都被绑在一个块点,你也应该消费进程
的输出只是使它导致进程停顿。 / p>
ps-我目前无法访问Windows机器,所以我不知道如果 Process#destory
将工作;)
I have a code that uses jDesktop to open a windows explorer interface when I clicked the button LOGIN and it's working right..
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
Desktop desktop = Desktop.getDesktop();
File dirToOpen;
try {
dirToOpen = new File("C://as//2010-0000-1");
desktop.open(dirToOpen);
} catch (IOException ex) {
ex.getMessage();
} catch (IllegalArgumentException iae) {
System.out.println("File Not Found");
}
}
then now, my problem is when I click the button LOGOUT, the jDesktop windows explorer interface should also be closed... I dont know what codes to use....
This is not so simple, they only chance you have is if you have a reference to the process in question. This is going to mean you're going to need to take more control over the process...This also means that it will only work on Windows...
I use the following code to show a specified file in Windows Explorer...
String path = file.getCanonicalPath();
ProcessBuilder pb = new ProcessBuilder("explorer.exe", "/select," + path);
pb.redirectError();
Process proc = pb.start();
Once you have access to the Process
, you can try using Process#destory
to try and terminate the process.
Launching the process should be done from a separate thread, so you don't get yourself all tied up in a block point, you should also consume the Process
's output just incase it causes the process to stall.
ps- I don't have access to a Windows machine at the moment, so I'm not sure if Process#destory
will work ;)
这篇关于如何关闭windows资源管理器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!