Why does Java's String.getBytes() uses “ISO-8859-1”

前端 未结 4 1603
广开言路
广开言路 2020-12-01 08:34

from java.lang.StringCoding :

String csn = (charsetName == null) ? \"ISO-8859-1\" : charsetName;

This is what is used from Java.lang.getByt

4条回答
  •  温柔的废话
    2020-12-01 08:55

    The parameterless String.getBytes() method doesn't use ISO-8859-1 by default. It will use the default platform encoding, if that can be determined. If, however, that's either missing or is an unrecognized encoding, it falls back to ISO-8859-1 as a "default default".

    You should very rarely see this in practice. Normally the platform default encoding will be detected correctly.

    However, I'd strongly suggest that you specify an explicit character encoding every time you perform an encode or decode operation. Even if you want the platform default, specify that explicitly.

提交回复
热议问题