One alternative along the same lines as what you're thinking is to reverse the String and read up to the first "/". This will separate out the file name and the path to the file. Then just reverse the two resulting Strings to get them back into usable form.
The best way is probably to just use
Java's File object to do the work for you.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/File.html You'll have to experiment a bit with it, but I think you want the File(String pathname) constructor. Then try the getPath() and getAbsolutePath() methods to see what results you get.
I'm not sure exactly what you're looking for or I'd provide an example. It's probably better for you to experiment anyway, since File is central to a lot of programming work in Java.