当前位置:编程学习 > JAVA >>

java String 转utf-8编码

[java] 
/**
    * Get XML String of utf-8
    * 
    * @return XML-Formed string
    */ 
    public static String getUTF8XMLString(String xml) { 
    // A StringBuffer Object 
    StringBuffer sb = new StringBuffer(); 
    sb.append(xml); 
    String xmString = ""; 
    String xmlUTF8=""; 
    try {   www.zzzyk.com
    xmString = new String(sb.toString().getBytes("UTF-8")); 
    xmlUTF8 = URLEncoder.encode(xmString, "UTF-8"); 
    System.out.println("utf-8 编码:" + xmlUTF8) ; 
    } catch (UnsupportedEncodingException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
    } 
    // return to String Formed 
    return xmlUTF8; 
    } 
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,