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));
    }//from   w  w  w.  j av a2 s.  c o 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;
    }
}