string - Remove filename from a URL/Path in java -


How do I remove a file name from a URL or string?

  string OS = System.getProperty ("os.name") toLowerCase () .; String Natal Dier = Game.clas.ptProcessingDemon (). GetCodeSource () GetLocation (). GetFile () ToString (); // string to & lt; Name & gt; Remove If (nativeDir.endsWith (".jar")) nativeDir = nativeDir.substring (0, nativeDir.lastIndexOf ("/")); // Load the correct files for the file: (new file (original file + .file separator + "Lib" + file. Separator + "original")). List files ()) {if (f.isDirectory () & amp; Amp; os.contains (f.getName (). ToLowerCase ()) {System.setProperty ("org.lwjgl.librarypath", f.getAbsolutePath ( )); break; }}   

That is what I have, and it works. I know that because I use "/", it will only work for windows. I want to make it platform independent.

You can remove the base path, file name, extension, etc. with any flavor of the file separator:

 < Code> string url = "c: \\ windows \\ system32 \\ cmd.exe"; String brace URL = filename utility path (url); String MyFile = Filename UT.getBaseName (url) + "." + File Name Availability Extension (url); Println (baseurl); Println (myFile);   

returns

  windows \ system32 \ cmd.exe   

with URL; string url = "C: /windows/system32/cmd.exe";

This must be done;

  windows / system32 / cmd exe    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -