public String getParentPath(final String originalPath) { boolean isSplitRequired = true; int lastSlashIndex = originalPath.lastIndexOf("/"); if (lastSlashIndex == -1 && lastSlashIndex == 0) { isSplitRequired = false; } return isSplitRequired ? originalPath.substring(0,lastSlashIndex) : originalPath; }