Windows-1251 to UTF-8 codes

2019-06-27 11:22发布

I have code of character in Windows-1251 code table. How i can get code of this character in UTF-8 code table?

For example i have character 'А' with coded in Windows-1251 equals 192, appropriate utf-8 code equals 1040

How i can to initialize Character or char in Java with code 192 from Windows-1251 code table?

char c = (char)192; //how to specify the encoding ?

1条回答
手持菜刀,她持情操
2楼-- · 2019-06-27 11:43

To convert a byte[] encoding in one character encoding to another you can do

public static byte[] convertEncoding(byte[] bytes, String from, String to) {
    return new String(bytes, from).getBytes(to);
}
查看更多
登录 后发表回答