Java - Write code to convert String from one CharSet to another CharSet

Requirements

Write code to convert String from one CharSet to another CharSet

Demo

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

public class Main {
    public static void main(String[] argv) {
        String src = "book2s.com";
        String set = "ASCII";
        String destSet = "UTF-8";
        System.out.println(convertCharSet(src, set, destSet));
    }//w w w  . j  a  v  a  2s  .co  m

    public static String convertCharSet(String src, String set,
            String destSet) {
        String result = src;
        try {
            if (set == null) {
                set = "iso-8859-1";
            }
            if (destSet == null) {
                destSet = "GBK";
            }
            result = new String(src.getBytes(set), destSet);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return result;
    }
}