Here is a very simple solution that was the best in my case:
private String getParent(String resourcePath) { int index = resourcePath.lastIndexOf('/'); if (index > 0) { return resourcePath.substring(0, index); } return "/"; }
I created a simple function, I was inspired by the File::getParent code. My code has no backslash issues on Windows. I assume that resourcePath is the resource part of the URL, without protocol, domain and port number. (e.g. /articles/sport/atricle_nr_1234 )
Tomasz Szymulewski
source share