java String 转utf-8编码

/**
	* 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 {
	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;
	}

你可能感兴趣的:(博文心得)