【发布时间】:2021-12-19 16:06:48
【问题描述】:
我试图做的是查看文件夹中是否已经存在同名文件。我曾尝试使用 file.exists 方法,但它只说明文件夹中是否存在文件。
if (option == JFileChooser.APPROVE_OPTION) {
file = new File(fileChooser.getSelectedFile().toString() + ".html");
try {
FileWriter writer = new FileWriter(file);
if (file.exists()) {
int ergebnis = JOptionPane.showConfirmDialog(TiltungsplanGUI.this,
"The File exists already. Overwrite?", "Meldung",
JOptionPane.YES_NO_OPTION);
if (ergebnis == JOptionPane.YES_OPTION) {
writer.write(r.getTilgungsplan());
}
}
writer.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(TiltungsplanGUI.this, e1.getMessage());
} catch (RatenRechnerException e1) {
// TODO Auto-generated catch block
JOptionPane.showMessageDialog(TiltungsplanGUI.this, e1.getMessage());
}
}
【问题讨论】:
-
您是否搜索过如何查看问题是否已存在?