java us ascii,在Java中,哪种编码方案是8位US ASCII?

本文探讨了在写入8位USASCII编码文件时,如何选择合适的方法如String.getBytes(),推荐UTF-8作为ASCII兼容首选,若需透明传输8位二进制数据则考虑ISO-8859-1。注意,大多数情况下需处理任意字符串,编码选择至关重要。

I want to write a string 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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值