我试图通过这样的东西(使用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.我做错了什么?