我正在使用JFileChooser浏览文件夹,但是当我选择文件夹时,它返回所选文件夹的上一级目录路径。
例如,我选择了“C:\ Test”,它会返回“C:\”。
这是我正在使用的代码。
这是我正在使用的代码。
JFileChooser c = new JFileChooser();
c.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
int rVal = c.showSaveDialog(c);
if (rVal == JFileChooser.APPROVE_OPTION) {
txtDirectory.setText("");
CC_Test.MsgBox(c.getCurrentDirectory().toString());
txtDirectory.setText(c.getCurrentDirectory().toString());
}
if (rVal == JFileChooser.CANCEL_OPTION) {
txtDirectory.setText("");
}