Java String to Byte Array getBytes(String str)

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

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(String str) 

Method Source Code

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

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

    public static byte[] getBytes(String str) {
        if (str != null) {
            try {
                return str.getBytes(CHARSET_NAME);
            } catch (UnsupportedEncodingException e) {
                return null;
            }//from   w  w w.  jav  a 2s  .c om
        } else {
            return null;
        }
    }
}

Related

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