[英]Open up windows explorer in java
I have been looking for an answer to this on Stack Overflow, but I couldn't find an answer that worked for me. 我一直在寻找Stack Overflow上的答案,但我找不到适合我的答案。
Using Java, how do I create a button that will launch an Explorer Window to a specified directory? 使用Java,如何创建一个按钮,将一个Explorer窗口启动到指定的目录? If this is possible, how do I make it work for OSX and Linux?
如果可以,我该如何使其适用于OSX和Linux?
I am not sure how it works in other OS but in Windows you can use something like this 我不确定它在其他操作系统中如何工作,但在Windows中你可以使用这样的东西
Desktop.getDesktop().open(new File("c:\\"));
Found another way (check link to FileExplorer class from that answer). 找到另一种方法 (从该答案检查FileExplorer类的链接)。 Also you can use
System.getProperty("os.name")
to determine operation system. 您还可以使用
System.getProperty("os.name")
来确定操作系统。
javax.swing.JButton myButton = new javax.swing.JButton("BUTTON TEXT");
myButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
java.awt.Desktop.getDesktop().open(new java.io.File("MY PATH NAME HERE"));
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.