Java UTF8 Encode toUTF8Bytes(String string)

Here you can find the source of toUTF8Bytes(String string)

Description

to UTF Bytes

License

LGPL

Declaration

public static byte[] toUTF8Bytes(String string) 

Method Source Code


//package com.java2s;
/*//from   w ww .j a v a2  s  .co  m
 * Copyright (C) 2009 by Eric Herman <eric@freesa.org>
 * Use and distribution licensed under the
 * GNU Lesser General Public License (LGPL) version 2.1.
 * See the COPYING file in the parent directory for full text.
 */

import java.io.UnsupportedEncodingException;

public class Main {
    public static final String CHARSET_UTF_8 = "UTF-8";

    public static byte[] toUTF8Bytes(String string) {
        return toBytes(string, CHARSET_UTF_8);
    }

    public static byte[] toBytes(String string, String encoding) {
        try {
            return string.getBytes(encoding);
        } catch (UnsupportedEncodingException noAscii) {
            throw new IllegalArgumentException("Runtime does not support" + " encoding " + encoding, noAscii);
        }
    }
}

Related

  1. toUTF8(String string)
  2. toUTF8(String value)
  3. toUTF8ByteArray(char[] string)
  4. toUTF8Bytes(final String s)
  5. toUTF8Bytes(String src)
  6. toUTF8InputStream(String str)
  7. toUTF8String(byte[] b, int offset, int length)
  8. utf8Code(String str)
  9. Utf8codeCheck(String text)