标签:
代码:
package com.test; import java.io.UnsupportedEncodingException; public class ConvertEncodingFormat { /** * 转换字符串编码 */ public static String convertEncodingFormat(String str, String formatFrom, String FormatTo) { String result = null; if (!(str == null || str.length() == 0)) { try { result = new String(str.getBytes(formatFrom), FormatTo); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return result; } /** * test */ public static void main(String[] args) { String str = "你好,少年!"; // UTF-8转化编码格式为iso-8859-1 String str1 = convertEncodingFormat(str, "UTF-8", "iso-8859-1"); System.out.println(str1); // 再转化为UTF-8编码格式 String str2 = convertEncodingFormat(str1, "iso-8859-1", "UTF-8"); System.out.println(str2); } }
标签:
原文地址:http://www.cnblogs.com/zj0208/p/5850094.html