I draw an image on a panel by using `BufferedImage`, and now I want to export that image.

But how can I detect if the new file is created or replace the old one? right now my output is:

```
old filename: image.jpeg

new filename: image.jpeg.jpeg

```

How can I do it?? I put a detect code after the file is created, using `createNewFile` method, but it doesn't seem to work :( 

This is pattern that do the saving, user can choose various types of image (bmp, jpeg ...):
`imageFile` is `File`

```
private void saveImage(){
        JFileChooser savefile = new JFileChooser("~/");
        savefile.setFileSelectionMode(JFileChooser.FILES_ONLY);//Chose file only
        savefile.setFileFilter(new pngSaveFilter());//Save in PNG format
        savefile.addChoosableFileFilter(new jpegSaveFilter());//Save in JPEG format
        savefile.addChoosableFileFilter(new bmpSaveFilter());//Save in BMP format
        savefile.addChoosableFileFilter(new gifSaveFilter());//Save in GIF format
        savefile.setAcceptAllFileFilterUsed(false);
        int returnVal = savefile.showSaveDialog(null);//Show save dialog
        String EXT="";
        String extension="";
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            imageFile = savefile.getSelectedFile();
            extension = savefile.getFileFilter().getDescription();
            if (extension.equals("JPEG file images *.jpeg,*.JPEG")) {
                EXT = "JPEG";
                imageFile = new File(imageFile.getAbsolutePath() + ".jpeg");
            }
            if (extension.equals("PNG file images *.png,*.PNG")) {
                EXT = "PNG";
                imageFile = new File(imageFile.getAbsolutePath() + ".png");
            }
            if (extension.equals("Bitmap file images *.bmp,*.BMP")) {
                EXT = "BMP";
                imageFile = new File(imageFile.getAbsolutePath() + ".bmp");
            }
            if (extension.equals("GIF file images *.gif,*.GIF")) {
                EXT = "GIF";
                imageFile = new File(imageFile.getAbsolutePath() + ".gif");
            }
            try {
                if(imageFile != null){
                    topViewImagePanel.drawToSave();
                    System.out.println(imageFile.createNewFile());
                    //ImageIO.write(topViewImagePanel.getSavingImage(), EXT, imageFile);
                  // the code detection is below
                    if (imageFile.createNewFile()){
                        int value = JOptionPane.showConfirmDialog(null, "Image existed! Replace?", "Warning!", JOptionPane.YES_NO_OPTION);
                        if (value == JOptionPane.YES_OPTION){
                            imageFile.delete();
                            ImageIO.write(topViewImagePanel.getSavingImage(), EXT, imageFile);
                        }else if (value == JOptionPane.NO_OPTION){

                        }
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

```