public static String cleanFileName(String s){
  return s.replaceAll("[^a-zA-Z0-9\\._]+","_");
}

public static String cleanFileName ( String s ) { return s . replaceAll ( "[^a-zA-Z0-9\\._]+" , "_" ) ; }
make a string safely usable as a file name by removing all illegal characters ( and a few more ) .
