getCurrentDirectory()只返回上一个目录路径

时间:2017-09-08 17:55:31

标签: java jfilechooser

期望的输出: C:\ Users \用户MYNAME \桌面\ AFolder \

当前输出 C:\ Users \ MyName \ Desktop \

代码:

public String choosePath() throws IOException {
    String fullPath = "";
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new java.io.File("."));
    chooser.setDialogTitle("choosertitle");
    chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    chooser.setAcceptAllFileFilterUsed(false);

    if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
        File file = chooser.getCurrentDirectory();
        fullPath = file.getAbsolutePath(); // or getAbsolutePath()
    } else {
        System.out.println("No Selection ");
    }
    return fullPath;
}

当我运行代码并导航到C:\ Users \ MyName \ Desktop \ AFolder \返回的字符串是C:\ Users \ MyName \ Desktop \时,我希望它是C:\ Users \ MyName \ Desktop \ AFolder \

我做错了什么?

0 个答案:

没有答案