java字符串编码转换方法:
1 /** 2 * 将UTF-8编码参数转换成ISO-8859-1编码 3 */ 4 private String convertToISO_8859_1(String param) { 5 String result = null; 6 if (null != param && !"".equals(param)) { 7 try { 8 result = new String(param.getBytes("UTF-8"), "iso-8859-1"); 9 } catch (UnsupportedEncodingException e) { 10 e.printStackTrace(); 11 } 12 } 13 return result; 14 } 15 16 /** 17 * 将ISO-8859-1编码参数转换成UTF-8编码 18 */ 19 private String convertToUTF_8(String param) { 20 String result = null; 21 if (null != param && !"".equals(param)) { 22 try { 23 result = new String(param.getBytes("iso-8859-1"), "UTF-8"); 24 } catch (UnsupportedEncodingException e) { 25 e.printStackTrace(); 26 } 27 } 28 return result; 29 }
时间: 2024-11-09 09:24:40