title: How to save file using JFileChooser in Java?
body: <p>I have following code. It saves file but with empty content. What's wrong with it?</p>
  
  <pre><code>public void saveMap() {
      String sb = "TEST CONTENT";
      JFileChooser chooser = new JFileChooser();
      chooser.setCurrentDirectory(new File("/home/me/Documents"));
      int retrival = chooser.showSaveDialog(null);
      if (retrival == JFileChooser.APPROVE_OPTION) {
          try {
              FileWriter fw = new FileWriter(chooser.getSelectedFile()+".txt");
              fw.write(sb.toString());
          } catch (Exception ex) {
              ex.printStackTrace();
          }
      }
  }
  </code></pre>