1
Hello. I am developing a system where in a certain situation, I must save a file with a picture extension 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? Thanks in advance, now.
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();
}
}
}
}
It worked out! Thank you Avelino.
– user3000135
For nothing, I hope I’ve helped. :)
– Avelino