What I tried to do is to see if a file with the same name already exist in the folder. I have tried to use the method file.exists, but it only says if a file exists in the folder.
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());
}
}