/** 16 位 UCS 转换格式,Big Endian(最低地址存放高位字节)字节顺序 */ |
public static final String UTF_16BE = "UTF-16BE" ; |
/** |
* 将字符编码转换成UTF-16BE码 |
*/ |
public String toUTF_16BE(String str) throws UnsupportedEncodingException { |
return this .changeCharset(str, UTF_16BE); |
} |
/** |
* 字符串编码转换的实现方法 |
* |
* @param str |
* 待转换编码的字符串 |
* @param newCharset |
* 目标编码 |
* @return |
* @throws UnsupportedEncodingException |
*/ |
public String changeCharset(String str, String newCharset) |
throws UnsupportedEncodingException { |
if (str != null ) { |
// 用默认字符编码解码字符串。 |
byte [] bs = str.getBytes(); |
// 用新的字符编码生成字符串 |
return new String(bs, newCharset); |
} |
return null ; |
} |