private static String sanitizeString(String s){
  StringBuilder sb=new StringBuilder();
  for (int i=0; i < s.length(); i++) {
    char ch=s.charAt(i);
    if (((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z')) || ((ch >= '0') && (ch <= '9')))     sb.append(ch);
 else     sb.append('_');
  }
  return sb.toString();
}

private static String sanitizeString ( String s ) { StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < s . length ( ) ; i ++ ) { char ch = s . charAt ( i ) ; if ( ( ( ch >= 'A' ) && ( ch <= 'Z' ) ) || ( ( ch >= 'a' ) && ( ch <= 'z' ) ) || ( ( ch >= '0' ) && ( ch <= '9' ) ) ) sb . append ( ch ) ; else sb . append ( '_' ) ; } return sb . toString ( ) ; }
remove characters from s that are not safe to use in a filename .
