change Charset - Java Internationalization

Java examples for Internationalization:Charset

Description

change Charset

Demo Code


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

public class Main {
    public static void main(String[] argv) throws Exception {
        String str = "java2s.com";
        String newCharset = "java2s.com";
        System.out.println(changeCharset(str, newCharset));
    }/*from  ww  w  .  j a v a 2 s  .  co m*/

    public static String changeCharset(String str, String newCharset)
            throws UnsupportedEncodingException {
        if (str != null) {
            byte[] bs = str.getBytes();
            return new String(bs, newCharset);
        }
        return null;
    }

    public static String changeCharset(String str, String oldCharset,
            String newCharset) throws UnsupportedEncodingException {
        if (str != null) {
            byte[] bs = str.getBytes(oldCharset);
            return new String(bs, newCharset);
        }
        return null;
    }
}

Related Tutorials