convert from UTF-8 -> internal Java String format - Java java.lang

Java examples for java.lang:String UTF

Description

convert from UTF-8 -> internal Java String format

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String s = "java2s.com";
        System.out.println(convertFromUTF8(s));
    }//from   w w  w. ja v a2  s  .c  o  m

    /**
     * convert from UTF-8 -> internal Java String format
     * @param s the String
     * @return java string
     */
    public static String convertFromUTF8(String s) {
        String out = null;
        try {
            out = new String(s.getBytes("ISO-8859-1"), "UTF-8");
        } catch (java.io.UnsupportedEncodingException e) {
            return null;
        }
        return out;
    }
}

Related Tutorials