I can have the following filename with path:
/somepath/file
The file has no extension, so in Java getPath ends up returning the entire path and filename. Assuming that the last thing in the path/filename is always a filename, how can I extract the path? The simplest solution is just to look for the last forward slash. But is there a built-in API that gets it?
Edit: Mistake. I meant how do I extract the path (and not the filename). Sorry.
Use
lastIndexOf()andsubstring()Edit : Just found out the existence of
getParent()and it will give you that directory of the file directly.