0
我想使用JFileChooser來選擇一個文件夾。它返回父文件夾,而不是當前文件夾。 示例我選擇文件夾文檔,然後進行備份。 JFileChooser返回文件instad的備份。試圖使用JFileChooser來選擇文件夾
String getFilePath()
{
JFileChooser fc = new JFileChooser();
// fc.setCurrentDirectory(new File(System.getProperty("user.home")));
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
int returnVal = fc.showOpenDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File rt=fc.getCurrentDirectory();
String t=rt.getName();
return t;
}
return null;
}
使用getSelectedFile – MadProgrammer