Hello. I am developing a system where in a certain situation, I must save a file with an extension of figures created by me. If the file already exists, I check with the user if he wants to overwrite the existing file. How should I proceed? Thank you in advance.
private class SalvarArquivo implements ActionListener {
public void actionPerformed(ActionEvent e) {
Figura figura;
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Salvar como");
int retrival = fileChooser.showSaveDialog(null);
if (retrival == JFileChooser.APPROVE_OPTION) {
try {
String nome_arquivo = FileChooser.getSelectedFile().getAbsolutePath();
if (!nome_arquivo.endsWith(".xyz")) {
nome_arquivo += ".xyz";
}
File arquivo1 = new File(nome_arquivo);
PrintWriter pw = new PrintWriter(arquivo1);
for (int i = 0; i < figuras.size(); i++) {
figura = figuras.get(i);
pw.println(figura.toString());
}
pw.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}