I am using JFileChooser
to generate PDF file in the specified file location but my requirement is this when we generated PDF like d:\\test.pdf**
in the d drive location and we again try to generated the same PDF file **it is override the previous PDF file . The requirement is this they show message box to show it is already generated and generate the other PDF file name.like test1.pdf
my question
Code: apply for the button
JFileChooser dialog = new JFileChooser();
// chooser.setDialogType(JFileChooser.SAVE_DIALOG);
dialog.setCurrentDirectory(new java.io.File("."));
dialog.setDialogTitle("Save Backup");
dialog.setApproveButtonText("Save");
//disables the all filesoptioning here
dialog.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
dialog.setAcceptAllFileFilterUsed(false);
if (dialog.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
System.out.println("getCurrentDirectory(): " + dialog.getCurrentDirectory());
System.out.print("getSelectedFile() : " + dialog.getSelectedFile());
try {
String filePath = dialog.getSelectedFile().getPath();
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(filePath));
document.open();
document.add(new Paragraph(" hello"));
document.close();
} catch (Exception e) {
}
}