Java UTF8 From getUtf8Bytes(String str)

Here you can find the source of getUtf8Bytes(String str)

Description

Returns the passed string as a byte array containing the string in UTF-8 representation.

License

LGPL

Parameter

Parameter Description
str Java string

Return

UTF-8 byte array

Declaration

public static byte[] getUtf8Bytes(String str) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.UnsupportedEncodingException;

public class Main {
    /**/* w ww  .  java  2s.c o m*/
     * Returns the passed string as a byte array containing the
     * string in UTF-8 representation.
     * @param str Java string
     * @return UTF-8 byte array
     */
    public static byte[] getUtf8Bytes(String str) {
        try {
            return str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException uee) {
            return str.getBytes();
        }
    }
}

Related

  1. getUtf8Bytes(String s)
  2. getUTF8Bytes(String s)
  3. getUtf8Bytes(String s)
  4. getUTF8Bytes(String str)
  5. getUtf8Bytes(String str)
  6. getUTF8Stream(String s)
  7. getUTF8String(byte[] bytes)
  8. getUTF8String(byte[] bytes)
  9. getUTF8String(String input)