2013-12-16 61 views
0

我需要一种方法来打开Windows文件资源管理器,将文件上传到桌面应用程序。 我想要做的是按上传按钮,然后Windows资源管理器弹出,然后我选择一个文件上传到数据库 所以我问的是如何打开Windows资源管理器来做到这一点。我无法在java SE中找到任何这方面的参考。 如果你知道至少有任何的参考,这应该是足够的。使用Windows资源管理器上传文件

回答

1

使用下面的代码片段来实现你在找什么,

JFileChooser fc = new JFileChooser(); 
int returnVal = fc.showOpenDialog(FileChooserDemo.this); 
if (returnVal == JFileChooser.APPROVE_OPTION) { 
    File file = fc.getSelectedFile(); 
    //This is where a real application would open the file. 
    System.out.println("Opening: " + file.getName()); 
} else { 
    System.out.println("Open command cancelled by user."); 
} 
相关问题