Java - Write code to get string Size in GBK encoding

Requirements

Write code to get string Size in GBK encoding

Demo

//package com.book2s;
import java.io.*;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(stringSize(s));
    }//  w ww  .  j  av  a2s  .  c om

    public static int stringSize(String s) {
        try {
            String anotherString = new String(s.getBytes("GBK"),
                    "ISO8859_1");
            return anotherString.length();
        } catch (UnsupportedEncodingException ex) {
            ex.printStackTrace();
            return 0;
        }
    }
}