最佳答案
你可以这样做。
JFileChooser chooser = new JFileChooser();
if (targetFile != null) {
chooser.setSelectedFile(targetFile);
} else {
chooser.setSelectedFile(newFile("default.xyz"));
}
int option = chooser.showSaveDialog(null);
if (option == JFileChooser.APPROVE_OPTION) {
targetFile = chooser.getSelectedFile();
}
在工作目录中弹出一个“保存文件”对话框并显示default.xyz
关于java - 在FileDialog中设置文件名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32174573/