public static String getParentPath ( String path ) { if ( path == null ) return null ; path = path . trim ( ) ; if ( path . endsWith ( PATH_ROOT ) && path . length ( ) > 1 ) { path = path . substring ( 0 , path . length ( ) - 1 ) ; } int lastIndex = path . lastIndexOf ( PATH_ROOT ) ; if ( path . length ( ) > 1 && lastIndex > 0 ) { return path . substring ( 0 , lastIndex ) ; } return PATH_ROOT ; }
Fast get parent directory using substring