Jas*_*ier 0 java windows file-io swing windows-explorer
在Java中使用它可以将Windows资源管理器打开到C驱动器:
Desktop.getDesktop().open(new File("c:\\"));
Run Code Online (Sandbox Code Playgroud)
但是,我还需要此处突出显示的“打开文件”功能:http : //i.imgur.com/XfgnozF.jpg
有没有一种方法可以用Java实现(使用Windows资源管理器,而不是Swing的FileChooser)?
看一下使用JFileChooser并使用本机系统的外观:

public class NativeOpenDialogDemo {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
}
final JFrame frame = new JFrame("Open File Example");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JButton openButton = new JButton("Open");
openButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JFileChooser chooser = new JFileChooser();
if (chooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
// do something
}
}
});
frame.add(openButton);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
}
});
}
}
Run Code Online (Sandbox Code Playgroud)