title: Checking if file exists when saving file in Java Swing
body: <p>So, I am saving XML data in Java. I am allowing the user to choose to path and name. Now, if the file already exists, I want to prompt them with a message like: "Do you want to overwrite the current file?" Is there anyway I can do this? Thanks</p>
  
  <pre><code>JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory(new File("."));
      chooser.setApproveButtonText("Save");
      chooser.setDialogTitle("Save");
      FileFilter filter = new FileNameExtensionFilter("XML File",
              new String[] { "xml" });
      chooser.setFileFilter(filter);
      chooser.addChoosableFileFilter(filter);
      int r = chooser.showOpenDialog(this);
      if (r == JFileChooser.APPROVE_OPTION) {
          try {
              JAXBContext jaxbContext = JAXBContext.newInstance(Shapes.class);
              Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
              jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,
                      Boolean.TRUE);
              File XMLfile = new File(chooser.getSelectedFile().toString()
                      + ".xml");
              jaxbMarshaller.marshal(myShapes, XMLfile);
  
          } catch (JAXBException e) {
              e.printStackTrace();
          }
      }
  }
  </code></pre>