code: 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').append((int) c).append('x');
          }
        }
      }
      return sb.toString();
    }
docs: Returns a "clean" version of the given filename in which spaces have
  been converted to dashes and all non-alphanumeric chars are underscores.