选择想要打开的文件夹(或文件),并记录该文件夹(或文件)所对应的路径.如果写这个代码呢?

解决方案 »

  1.   

    JFileChooser 可以选择文件夹的。楼主去看下 JFileChooser的API吧很清晰
      

  2.   

    如果用JFileChooser,必须要选择到某个文件才可以,我想就选择到某个文件夹,如何做呢
      

  3.   

    JFileChooser
    public class JFileChooserextends JComponentimplements AccessibleJFileChooser provides a simple mechanism for the user to choose a file. For information about using JFileChooser, see How to Use File Choosers, a section in The Java Tutorial. The following code pops up a file chooser for the user's home directory that sees only .jpg and .gif images:     JFileChooser chooser = new JFileChooser();
        FileNameExtensionFilter filter = new FileNameExtensionFilter(
            "JPG & GIF Images", "jpg", "gif");
        chooser.setFileFilter(filter);
        int returnVal = chooser.showOpenDialog(parent);
        if(returnVal == JFileChooser.APPROVE_OPTION) {
           System.out.println("You chose to open this file: " +
                chooser.getSelectedFile().getName());
        }