经过百度,千篇一律的内容,如下:

1.java自带的API

 

打开文件:
File file=new File("c://test.pdf");
java.awt.Desktop.getDesktop().open(file);

 

打开目录:
File file=new File("c://test.pdf");
java.awt.Desktop.getDesktop().open(file.getParentFile());
 
在jdk1.6上测试失败,一执行这段代码,应用程序直接卡死,不知道是什么原因。
 
后又经过百度。
 
通过java直接执行cmd命令得以实现。
 
try {
String path="c:\\abc";
                    Runtime.getRuntime().exec("explorer.exe /select, "+path);
                } catch (Exception e1) {
                    JOptionPane.showMessageDialog(null, "打开目录失败!", "错误提示",JOptionPane.ERROR_MESSAGE);
                     
                }

 

 

相关文章:

  • 2022-01-17
  • 2021-11-17
  • 2022-12-23
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2021-12-10
猜你喜欢
  • 2022-12-23
  • 2021-08-25
  • 2021-05-02
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-11-01
相关资源
相似解决方案