==============================================================
//工具类
public class ConvertToolUtils { public static String gbk2iso(String src) { return convertEncoding(src, "GBK", "ISO-8859-1"); } public static String iso2gbk(String src) { return convertEncoding(src, "ISO-8859-1", "GBK"); } public static String convertEncoding(String source, String sourceEncoding, String targetEncoding) { try { if (source == null || source.equals("")) { return ""; } else { return new String(source.getBytes(sourceEncoding), targetEncoding); } } catch (Exception e) { return ""; } } public static int ConvertStrNum2IntNum(String strNum) { int Num = 0; try { if (null == strNum || strNum.trim().equals("")) { Num = 0; } else { Num = Integer.parseInt(strNum); }} catch (Exception e) {
Num = 0; e.printStackTrace(); } return Num; } } 使用方式:requestXML = ConvertToolUtils.convertEncoding(requestXML,"ISO8859-1","UTF-8");
=======================================
public String getUTF8XMLString(String xml) {// A StringBuffer ObjectStringBuffer sb = new StringBuffer();sb.append(xml);String xmString = "";String xmlUTF8 = "";try {xmString = new String(sb.toString().getBytes("UTF-8"));xmlUTF8 = URLEncoder.encode(xmString, "UTF-8");//加码//java.net.URLDecoder.decode(str,"UTF-8");//解码System.out.println("utf-8 编码:" + xmlUTF8);} catch (UnsupportedEncodingException e) {// TODO Auto-generated catch blocke.printStackTrace();}// return to String Formedreturn xmlUTF8;}
新闻热点
疑难解答