期望的输出: 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 \
我做错了什么?