您应该
FileChooser为此使用
。在这里看看:
//Create a file chooserfinal JFileChooser fc = new JFileChooser();...//In response to a button click:int returnVal = fc.showOpenDialog(aComponent);public void actionPerformed(ActionEvent e) { //Handle open button action. if (e.getSource() == openButton) { 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. log.append("Opening: " + file.getName() + "." + newline); } else { log.append("Open command cancelled by user." + newline); } } ...}


