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

public static String makeValidFileName ( String fileName ) { return fileName . replaceAll ( "[^a-zA-Z0-9_\\-\\.]" , "-" ) ; }
replace all invalid file characters with valid ones . example : himom ( * ) . txt becomes himom - - - . txt note some characters that will be replaced wouldn ' t really be invalid ( ' ' for example ) but a conservative approach is taken .
