将Windows-1257转换为ISO-8859-13 java字符集 [英] Convert Windows-1257 to ISO-8859-13 java charset

查看:132
本文介绍了将Windows-1257转换为ISO-8859-13 java字符集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字节数组,应该被转换成字符串。该阵列由Windows-1257编码文本组成。将此数组转换为字符串的最佳方式是什么?后来我需要将字符串转换为ISO-8859-13字节数组,但我知道如何使这部分工作。



我试过这样:

  String result = new String(currentByteArray,ISO-8859-13); 

但当然,在本地字符的地方也有垃圾。

解决方案

  String unicodeString = new String(currentByteArray,Windows-1257); 
byte [] result = unicodeString.getBytes(ISO-8859-13);

  PrintWriter out = new PrintWriter(文件ISO-8859-13); 

Java非常简单:String / Reader& Writer是能够包含所有字符的Unicode文本。
和二进制字节[] s / InputStream& OutputStream是二进制数据。



因此,字符串的String构造函数需要这些字节的原始编码,
和获取字节需要这些字节应该在哪里编码。



请注意,有一个参数的重载版本没有编码。这使用平台编码;不便携式。


I have array of bytes that should be converted to string. That array consists of Windows-1257 encoded text. What is the best way of converting this array to string? Later I will need to convert string to ISO-8859-13 byte array, but I know how to make this part of job.

I tried like this:

String result = new String(currentByteArray, "ISO-8859-13");

But of course got garbage in local character places.

解决方案

String unicodeString = new String(currentByteArray, "Windows-1257");
byte[] result = unicodeString.getBytes("ISO-8859-13");

or

PrintWriter out = new PrintWriter(file, "ISO-8859-13");

Java is very simple: String/Reader&Writer is Unicode text capable to contain all characters. And binary byte[]s/InputStream&OutputStream is for binary data.

Hence the String constructor for bytes needs the original encoding of those bytes, and getting bytes needs the encoding where those bytes should be in.

Be aware that there are overloaded versions with one parameter, without encoding. That uses the platform encoding; not-portable.

这篇关于将Windows-1257转换为ISO-8859-13 java字符集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆