0

我创建了一个 JFileChooser,我用它来定位要保存到的文件的目录。

saveChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
saveChooser.showSaveDialog(null);
String exportPath = saveChooser.getCurrentDirectory() + "\\exportedData.txt";
System.out.println(exportPath);

(然后我使用 exportPath 作为我的文件编写器)

当我在 JFileChooser 中选择 C:\Users\'me'\Eclipse\workspace\'project'\files 时,输出为 C:\Users\'me'\Eclipse\workspace\'project'\exportedData.txt

我试过保存到多个位置。似乎它总是删除最后一个目录。但是,当我选择根 C:\ 时,它使用我认为的默认值 My Documents。我知道这可能不是保存文件的最佳方式,并且会带来一些错误,抱歉。(文件名和扩展名在代码中设置)。

4

1 回答 1

0

我猜你想要 saveChooser.getSelectedFile(),在这种情况下,选定的文件实际上是一个目录。希望是对的,没有测试。

于 2009-11-28T23:57:46.790 回答