title: Full path of saved file in Java
body: <p>I want to get the full path of the file that the user saved in Java.
  Here is the code of the method save and it works okay but actually i need to get the path that the user had save his file in. Could someone help me:</p>
  
  <pre><code>import java.awt.*;
  import java.io.*;
  import javax.swing.*;
  
  public class FileChooserSave {
      private static void createAndShowUI() {
          final JFileChooser chooser = new JFileChooser(new File(".")) {
              public void approveSelection() {
                  if (getSelectedFile().exists()) {
                      int n = JOptionPane.showConfirmDialog(this, "Do You Want to Overwrite File?", "Confirm Overwrite",
                              JOptionPane.YES_NO_OPTION);
  
                      if (n == JOptionPane.YES_OPTION)
                          super.approveSelection();
  
                  } else
                      super.approveSelection();
              }
          };
  
          chooser.setSelectedFile(new File(""));
          int returnVal = chooser.showSaveDialog(null);
  
          if (returnVal == JFileChooser.APPROVE_OPTION) {
              System.out.println(chooser.getSelectedFile());
          }
      }
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              public void run() {
                  createAndShowUI();
              }
          });
      }
  }
  </code></pre>