title: Remove filename from a URL/Path in java
body: <p>How do I remove the file name from a URL or String?</p>
  
  <pre><code>String os = System.getProperty("os.name").toLowerCase();
          String nativeDir = Game.class.getProtectionDomain().getCodeSource().getLocation().getFile().toString();
  
          //Remove the &lt;name&gt;.jar from the string
          if(nativeDir.endsWith(".jar"))
              nativeDir = nativeDir.substring(0, nativeDir.lastIndexOf("/"));
  
          //Load the right native files
          for(File f : (new File(nativeDir + File.separator + "lib" + File.separator + "native")).listFiles()){
              if(f.isDirectory() &amp;&amp; os.contains(f.getName().toLowerCase())){
                  System.setProperty("org.lwjgl.librarypath", f.getAbsolutePath()); break;
              }
          }
  </code></pre>
  
  <p>That's what I have right now, and it work. From what I know, because I use "/" it will only work for windows. I want to make it platform independent</p>