开发者

in Java, which encoding scheme is 8-bit US ASCII?

I want to write a stri开发者_C百科ng to a file which expects an 8-bit US ASCII encoding.

Which encoding scheme should I use for the method String.getBytes(encodingScheme)?

Thanks.


ASCII is a 7bit encoding scheme, there is no "8-bit ASCII".

However, many encodings are ASCII-compatible, and some are 8bit transparent (i.e. every binary series maps to a valid character string, and vice versa, useful if you're sending binary data over a character channel without encoding it in base64 or so). If you just want to be ASCII-compatible, UTF-8 is the best choice; if you need 8 bit transparency, ISO-8859-1.

Note that the above advice is only useful if you want to transport ASCII-only strings or 8bit binary ones. In most cases, you actually want to transfer arbitrary strings, and there's no way around finding the proper encoding for these.


US-ASCII

The list of encodings is here: https://docs.oracle.com/javase/8/docs/technotes/guides/intl/encoding.doc.html


There's no such thing as "8-bit ASCII". There are several 8-bit "extensions" to ASCII, including ISO-8859-1 and Windows-1252. Those are probably the most common ones, but they're not the same. You really need to find out exactly which encoding is expected.

Both of those names are available via those names in Java - at least they are on my JDK installation. (You may find that Windows-1252 isn't available on a Linux installation, for example.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜