【问题标题】:JFileChooser returns not all pathJFileChooser 并非返回所有路径
【发布时间】:2011-05-24 01:44:36
【问题描述】:

使用以下方法点击路径按钮:

public static void pathButtonAction() {
    JFileChooser chooser = new JFileChooser();
    if (pathToInbound == null) { //private static File pathToInbound;
    chooser.setCurrentDirectory(new java.io.File("."));
    } else {chooser.setCurrentDirectory(pathToInbound);
            }

    chooser.setDialogTitle("Choose folder with messages to send");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);
    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        pathToInbound = chooser.getCurrentDirectory(); 
        addLogText(chooser.getCurrentDirectory().getAbsolutePath());
    }


}

但在这里我选择文件夹 c:\windows\temp 这里 addLogText(chooser.getCurrentDirectory().getAbsolutePath()) 我只记录 c:\windows。为什么临时文件夹被忽略/截断?

【问题讨论】:

    标签: java directory jfilechooser


    【解决方案1】:

    您应该调用chooser.getSelectedFile() 而不是chooser.getCurrentDirectory(),这将返回用户在文件选择器中导航的当前目录。在您的情况下,它是C:\Windows

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多