小编fer*_*090的帖子

jfilechooser - 将目录设置为文件中的路径

我试图通过这样的东西(使用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);
Run Code Online (Sandbox Code Playgroud)

我正在使用getCanonicalPath()来获取路径并写入文件path.txt

path = file.getCanonicalPath();
Run Code Online (Sandbox Code Playgroud)

我不打算把我的所有代码放在这里,但我确信程序会在path.txt中写入和读取路径.我没有收到任何错误,但每次运行程序时,它总是在我的文件夹中打开JFilechooser.我做错了什么?

java swing jfilechooser

15
推荐指数
2
解决办法
5万
查看次数

标签 统计

java ×1

jfilechooser ×1

swing ×1