Java tutorial
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { private static int getBytesLength(String msg) { try { return msg.getBytes("GB2312").length; } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; } }