I am working on a program that loads and saves data from text files, and I am asking the user a file name with JFileChooser on load and save.
This question is about the save dialog: new JFileChooser().showSaveDialog();
. The user then could overwrite an existing file without any warning, and that would be a problem.
Any suggestion on how to fix this? I have been looking for some method or option, but I didn't found anything.
Thanks in advance.
Thanks for the answers, but I found another workaround, overriding the approveSelection() of the JFileChooser, this way:
I hope this could be useful for someone else.
I wrote this based on your own answer. Posted in case someone else finds it useful:
As AvrDragon said, closing with X is not handled. I added a default case to handle all unrelevant options:
Check before saving if the same file already exist then ask user for confirmation does she really want to override :p
here is code
To check file already exist use
Maybe you could verify that the file does not already exists, and even give the JFileChooser a
FileSystemView
(see this constructor)