title: How to get name of File object without its extension in Java?
body: <p>I am trying to get name of a <code>File</code> object without its extension, e.g. getting "vegetation" when the filename is "vegetation.txt." I have tried implementing this code:</p>
  
  <pre><code>openFile = fileChooser.getSelectedFile();
  String[] tokens = openFile.getName().split(".");
  String name = tokens[0];
  </code></pre>
  
  <p>Unfortunately, it returns a <code>null</code> object. There is a problem just in the defining the <code>String</code> object, I guess, because the method <code>getName()</code> works correctly; it gives me the name of the file with its extension.  </p>
  
  <p>Do you have any idea?</p>