JFileChooser将当前目录设置为Homegroup或Network

问题描述 投票:-2回答:1

我想在打开对话框时直接转到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;
}

此代码无法正常工作。非常感谢你...

java network-programming jfilechooser
1个回答
0
投票

问题是您提供了无效的URI,从而获得了URISyntaxException。尝试更干净,更高效的访问现有文件的东西,或学习URI语法:

fc.setCurrentDirectory(new File(System.getProperty("user.home")));
© www.soinside.com 2019 - 2024. All rights reserved.