title: Set default saving extension with JFileChooser
body: <p>I'm trying to save a file using <code>JFileChooser</code>. However, I seem to be having some trouble with it. Here's my code:</p>
  
  <pre><code>    if (e.getSource() == saveMenu) {
  
          JFileChooser chooser = new JFileChooser();
          chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
  
          FileNameExtensionFilter xmlFilter = new FileNameExtensionFilter("xml files (*.xml)", "xml");
          // add filters
          chooser.addChoosableFileFilter(xmlFilter);
          chooser.setFileFilter(xmlFilter);
  
          int result = chooser.showSaveDialog(Simulation.this);
  
          if (result == chooser.APPROVE_OPTION) {
              writeToXML(chooser.getSelectedFile());
          }
  
      }
  </code></pre>
  
  <p>This doesn't force the file to have a <code>.xml</code> extension, so I've tried to use the following code to force the file to be saved with the extension .xml</p>
  
  <pre><code>     OutputFormat format = OutputFormat.createPrettyPrint();
       format.setEncoding("UTF-8");
       XMLWriter xmlWriter = null;
       try {              
           xmlWriter = new XMLWriter(new OutputStreamWriter(
                   new FileOutputStream(f+".xml"), "UTF8"),
                   format);
  </code></pre>
  
  <p>However, with this I can't prevent the user from writing <code>xpto.xml</code> in the <code>JFileChooser</code> and if they do that, the file will have "two extensions": it will be a file named <code>xpto.xml.xml</code></p>
  
  <p>So my questions are:</p>
  
  <ul>
  <li>How can I make the <code>JFileChooser</code> save an xml file by default?</li>
  <li>If the user inserts a file name like xpto.xml, how can I save it as xpto.xml and not xpto.xml.xml?</li>
  </ul>