JFileChooser 返回并非所有路径
在“路径”按钮上使用以下方法单击:
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。为什么临时文件夹被忽略/截断?
using following method on Path button click:
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());
}
}
But here i choose folder c:\windows\temp
Here addLogText(chooser.getCurrentDirectory().getAbsolutePath()) i get to log only c:\windows. Why temp folder was ignored/truncated?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该调用
chooser.getSelectedFile()
而不是chooser.getCurrentDirectory()
,这会返回用户在文件选择器中导航的当前目录。在您的情况下,它是C:\Windows
。You should call
chooser.getSelectedFile()
instead ofchooser.getCurrentDirectory()
, this returns the current directory where the user has navigated in the filechooser. In your case it isC:\Windows
.