public static String cleanPathSegment(final String toClean){
  final String cleaned=toClean.replaceAll("[.\\\\/:*?\"<>|\\[\\]\\(\\)]","");
  if (cleaned.length() == 0)   throw new IllegalStateException("Path segment " + toClean + " has not valid characters and is thus empty");
  return cleaned;
}

public static String cleanPathSegment ( final String toClean ) { final String cleaned = toClean . replaceAll ( "[.\\\\/:*?\"<>|\\[\\]\\(\\)]" , "" ) ; if ( cleaned . length ( ) == 0 ) throw new IllegalStateException ( "Path segment " + toClean + " has not valid characters and is thus empty" ) ; return cleaned ; }
removes characters that aren ' t acceptable in a file path ( mostly for windows ) .
