the android app can load the absolute image path form the sdcard, which looks like this/storage/sdcard0/DCIM/Camera/20130622_200703.jpg
I only need part of the path string like/20130622_200703.jpg
So I want to recursively split the absolute path into the one I need. I wrote the code like below
public String splitPath(String path){
if (path == "") {
return null;
}
if(path.indexOf("/") != -1){
String subPath = path.substring(path.indexOf("/") + 1);
//absoultePath = subPath;
splitPath(subPath);
}
return path;
}
But the problem is when I following the process in Debug mode. the path could be split from /.../.../.../.../... to /... which is correct, but it did not return the path even when path.indexOf("/") equals -1.
Then weird things happened, the recursive loop did not end, it continued to change the /... to /.../.../.../.../... step by step, after that process, it returned the path, which was exactly the same value like /storage/sdcard0/DCIM/Camera/20130622_200703.jpg.
I really confused about that, it feels like the logic itself playing joke on me. Oops
Any feedback from you will be appreciated.
"/" + new File(path).getName();? Wouldnt that solve the problem?