Java String to Byte Array getBytes(String str)

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

Description

Get the bytes with UTF-8

License

Apache License

Parameter

Parameter Description
str a parameter

Declaration

public static byte[] getBytes(String str) 

Method Source Code


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

import java.io.UnsupportedEncodingException;

public class Main {
    /**/*from ww w  . ja va  2  s  .  c om*/
     * Get the bytes with UTF-8
     * @param str
     * @return
     */
    public static byte[] getBytes(String str) {
        if (str == null) {
            return null;
        }
        try {
            return str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return null;
    }
}

Related

  1. getBytes(String s)
  2. getBytes(String s)
  3. getBytes(String s, String charsetName)
  4. getBytes(String s, String encoding)
  5. getBytes(String s, String encoding)
  6. getBytes(String str)
  7. getBytes(String str)
  8. getBytes(String str)
  9. getBytes(String str)