开发者

How to encode character in Microsoft Windows Codepage 1251 (Cyrl) in java

开发者 https://www.devze.com 2023-02-15 20:28 出处:网络
I want to encode string in Java with Microsoft Windows Codepage 1251 (Cy开发者_运维问答rl) table.You don\'t have to \"encode\" a string. When you turn a string from/to bytes you need to decode/encode

I want to encode string in Java with Microsoft Windows Codepage 1251 (Cy开发者_运维问答rl) table.


You don't have to "encode" a string. When you turn a string from/to bytes you need to decode/encode them. So you actually encode a binary array.

byte[] cp1251encodedBytes = "your characters".getBytes(Charset.forName("Cp1251"));

List of supported encodings: http://download.oracle.com/javase/1.4.2/docs/guide/intl/encoding.doc.html

Update: updated to Charset.forName() as McDowell commented.

0

精彩评论

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