code: public static String replaceRestrictedCharactersInFileName(String name) {
          int replacedChars = 0;
          StringBuilder sb = new StringBuilder(name.length());
          for (int x = 0; x < name.length(); x++) {
              char y = name.charAt(x);
              if ((FILE_NAME_RESTRICTED_CHARS.indexOf(y) == -1) &&
                  ((y < 0) || (y > 31))) /* Exclude control characters */ {
                  sb.append(y);
              } else {
                  sb.append('.');
                  replacedChars++;
              }
          }
  
          String processedName = sb.toString();
          if ((processedName.length() <= 2) && (replacedChars > 0) &&
              (processedName.equals(".") || processedName.equals(".."))) {
              return null;
          }
  
          return ((name.length() - replacedChars) > 0) ? processedName : null;
      }
docs: Copy a file name, replacing each restricted character with a single period
  character ('.').
  
  Restricted characters are control characters and the following:
  
  <pre>
  &lt; &gt; : " / \\ | ? *
  </pre>
  
  (See {@link #FILE_NAME_RESTRICTED_CHARS}.
  
  Control characters are character with a value greater than or equal to zero
  and less than or equal to 31.
  
  The set of restricted characters was selected conservatively based on the
  rules for Windows file names.
  
  The parameter should be a file name. Both the forward slash ('/') and
  the backwards slash ('\\') are restricted characters.
  
  Answer null if all characters of the file name are replaced, or if the resulting
  file name is "." or "..".
  
  @param name The file name in which to replace restricted characters. An exception
  will be thrown if the file name is null.
  
  @return The copy of the file name with all restricted characters replaced. Null
  if all characters were replaced or of the replaced file name is "." or "..".