Java JFileChooser不会返回所有路径
在路径按钮上使用以下方法单击:Java JFileChooser不会返回所有路径,java,directory,jfilechooser,Java,Directory,Jfilechooser,在路径按钮上使用以下方法单击: public static void pathButtonAction() { JFileChooser chooser = new JFileChooser(); if (pathToInbound == null) { //private static File pathToInbound; chooser.setCurrentDirectory(new java.io.File(".")); } else {chooser.s
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。为什么临时文件夹被忽略/截断?您应该调用
chooser.getSelectedFile()
而不是chooser.getCurrentDirectory()
,这将返回用户在文件选择器中导航的当前目录。在您的情况下,它是C:\Windows