code: private static String convertToNativeEncoding(String fileName, boolean isPath) {
          String ret = fileName;
  
          ret = removeIllegalCharacters(ret, isPath);
  
          //convert our filename to OS encoding...
          try {
              final CharsetEncoder charsetEncoder = Charset.defaultCharset().newEncoder();
              charsetEncoder.onMalformedInput(CodingErrorAction.REPLACE); // otherwise breaks on first unconvertable char
              charsetEncoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
              charsetEncoder.replaceWith(new byte[]{'_'});
  
              final ByteBuffer buf = charsetEncoder.encode(CharBuffer.wrap(ret));
              if (buf.hasArray()) {
                  ret = new String(buf.array());
              }
  
              //remove NUL character from conversion...
              ret = ret.replaceAll("\\u0000", "");
          } catch (CharacterCodingException e) {
              e.printStackTrace();
          }
  
          return ret;
      }
docs: Convert a filename from Java´s native UTF-16 to OS native character encoding.
  
  @param fileName The UTF-16 filename string.
  @return Natively encoded string for the OS.