title: Print folder name where file originated from
body: <p>I'm trying to print a folder name where a file is stored.</p>
  
  <p>Example: 
  I have the file picture.jpg
  Stored in the path C:\Users\Desktop\Foldername\picture.jpg</p>
  
  <p>Is it possible to print "Foldername". I've tried a substring but that seems to rely on me hard-coding the character number in. EG:</p>
  
  <pre><code>System.out.println(path.substring(33, 38));
  </code></pre>
  
  <p>If my program was to be released, and the user had a different file path - this would offset the substring.</p>
  
  <p>To select the file, my program has the following code</p>
  
  <pre><code>chooser = new JFileChooser();
          chooser.setCurrentDirectory(new java.io.File(computerUsername+"\\Desktop\\Foldername"));
          chooser.setDialogTitle(choosertitle);
          chooser.setAcceptAllFileFilterUsed(true);
  </code></pre>
  
  <p>Therefore, the below code prints out a nullpointexpection error.
      chooser.getPath().getName();</p>