下边这个方法是实现选择目录的,但我现在想选择目录下的目录。例如目录结构为:a/b/c,当前目录为a,我要选择c目录怎么实现呀?下面这个方法不行。
private String browsePath()
{
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(this.mode.getTomcatFile()));
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);// 只能选择目录
String path = "";
if (fc.showDialog(this, "打开") == JFileChooser.APPROVE_OPTION)
{
path = fc.getSelectedFile().getAbsolutePath();
}
return path;
}thank you
private String browsePath()
{
JFileChooser fc = new JFileChooser();
fc.setCurrentDirectory(new File(this.mode.getTomcatFile()));
fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);// 只能选择目录
String path = "";
if (fc.showDialog(this, "打开") == JFileChooser.APPROVE_OPTION)
{
path = fc.getSelectedFile().getAbsolutePath();
}
return path;
}thank you
只选择目录是JFileChooser.DIRECTORIES_ONLY吧
你要同时又可以选择文件又可以选择目录?
我要实现选择目录下的目录
昨天下班回家了
今天来试了一下
JFileChooser fileChooser = new JFileChooser(".");
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fileChooser.showOpenDialog(AFrame.this);
System.out.println(fileChooser.getSelectedFile());
这样就可以点打开后返回当前目录了