In Objective-C I use -[NSURL URLByDeletingLastPathComponent] to get parent URL. What\'s the equivalent of this in Java?
Here is very simple solution which was the best approach in my use case:
private String getParent(String resourcePath) {
int index = resourcePath.lastIndexOf('/');
if (index > 0) {
return resourcePath.substring(0, index);
}
return "/";
}
I created simple function, I was inspired by the code of File::getParent. In my code there is no issue with back slashes on Windows. I assume that resourcePath is resource part of URL, without protocol, domain and port number. (e.g. /articles/sport/atricle_nr_1234 )