简体   繁体   English

在java中打开Windows资源管理器

[英]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:\\"));

Edit 编辑

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.

相关问题 Java .jar“打开方式” Windows资源管理器不断产生资源管理器进程 - Java .jar “Open With” Windows Explorer continually spawns Explorer processes 如何使用Java在Windows资源管理器中打开映射的网络驱动器 - How to open mapped network Drive in windows explorer using java 如何使用 java swing 中的 windows 资源管理器上下文菜单打开.txt? - How to open .txt using windows explorer context menu in java swing? 打开资源管理器 - java - Open Explorer - java 尝试从 windows 资源管理器打开 a.java 文件时,我收到“找不到可打开文件的项目”错误消息 - When trying to open a .java file from windows explorer I get a “No project found to open file in” error message java中的Windows资源管理器上下文菜单 - windows explorer context menu in java 使用Java创建的ZIP文件,在Windows资源管理器中打开时显示为空 - ZIP file created using Java showing empty when open with Windows Explorer Java在Windows资源管理器中选择文件? - Java Select File in windows Explorer? 如何使用java代码打开Windows文件浏览器并突出显示指定的文件? - How to use java code to open Windows file explorer and highlight the specified file? 从 IntelliJ 在 Windows 资源管理器中打开包含目录 - Open containing directory in Windows Explorer from IntelliJ
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM