public static String cleanPath ( String path ) { if ( path . endsWith ( SEPARATOR ) ) { path = path . replaceAll ( SEPARATOR + "+$" , "" ) ; } if ( path . startsWith ( SEPARATOR ) ) { path = path . replaceAll ( "^" + SEPARATOR + "+" , "" ) ; } return path . replaceAll ( "/+" , SEPARATOR ) ; }
Clean the path string by removing leading and trailing slashes and removing duplicate slashes .