Obtain name from absolute path, substring from last slash, java android
android, file, java
Solution
You should go via the `File` api. Quoted from the `File.getName()` documentation:
Returns the name of the file or directory denoted by this abstract pathname. This is just the last name in the pathname's name sequence. If the pathname's name sequence is empty, then the empty string is returned.
Example:
String name = new File("/mnt/sdcard/Videos/Videoname").getName();
Problem
I want to extract the name of an absolute path. If I have a string with the value /mnt/sdcard/Videos/Videoname, I want to save a string with the value Videoname. The string is changing and I can't obtain previously the number of slashes. How could I split a substring from the last slash? /mnt/sdcard/Videos/Videoname --> Videnoname