我想在打开对话框时直接转到Homegroup。谢谢。
JFileChooser fc = null;
try {
fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setCurrentDirectory(new File(new URI("file:C:\\" + "..\\Homegroup")));
fc.showOpenDialog(parent);
return fc.getSelectedFile().getAbsolutePath();
} catch (Exception e) {
return null;
}
此代码无法正常工作。非常感谢你...
问题是您提供了无效的URI,从而获得了URISyntaxException。尝试更干净,更高效的访问现有文件的东西,或学习URI语法:
fc.setCurrentDirectory(new File(System.getProperty("user.home")));