public static String fileNameClean(String s){
  char[] chars=s.toCharArray();
  StringBuilder sb=new StringBuilder();
  for (  char c : chars) {
    if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9')|| (c == '_')) {
      sb.append(c);
    }
 else {
      if (c == ' ' || c == '-') {
        sb.append('_');
      }
 else {
        sb.append("x" + (int)c + "x");
      }
    }
  }
  return sb.toString();
}

public static String fileNameClean ( String s ) { char [ ] chars = s . toCharArray ( ) ; StringBuilder sb = new StringBuilder ( ) ; for ( char c : chars ) { if ( ( c >= 'A' && c <= 'Z' ) || ( c >= 'a' && c <= 'z' ) || ( c >= '0' && c <= '9' ) || ( c == '_' ) ) { sb . append ( c ) ; } else { if ( c == ' ' || c == '-' ) { sb . append ( '_' ) ; } else { sb . append ( "x" + ( int ) c + "x" ) ; } } } return sb . toString ( ) ; }
returns a " clean " version of the given filename in which spaces have been converted to dashes and all non - alphaneumeric chars are underscores .
