【发布时间】:2011-04-19 19:19:35
【问题描述】:
我正在尝试通过类似这样的方式(使用 commons-io)在 JFilechooser 中设置目录路径:
String fileContents = IOUtils.toString(new FileInputStream("path.txt"));
File theDirectory = new File(fileContents);
filechooser = new JFileChooser();
fileChooser.setCurrentDirectory(theDirectory);
filechooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
我使用getCanonicalPath()获取路径并写入文件path.txt
path = file.getCanonicalPath();
我不打算把我所有的代码都放在这里,但我确信程序会在 path.txt 中写入和读取路径。 我没有收到任何错误,但每次我运行程序时,它总是在我的文档文件夹中打开 JFilechooser。我做错了什么?
【问题讨论】:
-
您是否尝试打印出
theDirectory以及它是否存在?System.out.println( theDirectory.getCanonicalPath() + " exists: " + theDirectory.exists() );如果文件不再存在,则文件选择器将默认为 My Documents 文件夹。
标签: java swing jfilechooser