title: JFileChooser delivers file name as null
body: <p>I've been writing an audio/video converter in Java. Everything is working smoothly, except for the JFileChooser. (I use AWT FileDialog usually for choosing files but can't use it in this project because I've heard FileDialog is OS Dependent-please advise.)</p>
  
  <p>Here's how my File selection process works:</p>
  
  <ul>
  <li><p>I've defined a public String fileLocn. fileLocn will contain the location of the file selected.</p></li>
  <li><p>My program uses Swing. There is a JButton which will open the JFIleChooser, called FilePicker. Here is the code for the FilePicker as follows:</p>
  
  <pre><code>private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
  // TODO add your handling code here:
  JFileChooser FilePicker=new JFileChooser();
  int returnVal = FilePicker.showOpenDialog(this);
  if (returnVal == JFileChooser.APPROVE_OPTION) {
  File file=FilePicker.getSelectedFile();
  formatpanel.setEnabled(true);
  fileLocn=FilePicker.getCurrentDirectory().toString()+"\\"+FilePicker.getName();
  filelocation.setText(fileLocn);
  }
  </code></pre></li>
  <li><p>The FilePicker selects the file and supplies it's location to the string fileLocn, which is used as the location for another file. Please note that the filelocation TextField is ornamental and not used in the main code.</p></li>
  </ul>
  
  <p>This is where the problem arises. The getCurrentDirectory() command is working correctly, but the getName() command is being delivered as null. So, if I select a file FQSEMI.mp4 in the "Videos" folder of my C: drive, it is shown as C:\Videos\null rather than the desired C:\Videos\FQSEMI.</p>
  
  <p>Please point out what is wrong with my code. Thank you.</p>
  
  <p>(P.S. Guaranteed upvote to relevant answers and I'll mention you in the credits :) )</p>