Java String to Byte Array getBytes(String str, String charset)

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

Description

get Bytes

License

Apache License

Return

the value of str.getBytes() without the idiotic checked exception

Declaration

public static byte[] getBytes(String str, String charset) 

Method Source Code


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

import java.io.UnsupportedEncodingException;

public class Main {
    /**//  w w w  .j  a  v  a  2  s. c  o m
     * @return the value of str.getBytes() without the idiotic checked exception
     */
    public static byte[] getBytes(String str, String charset) {
        try {
            return str.getBytes(charset);
        } catch (UnsupportedEncodingException ex) {
            throw new IllegalArgumentException(charset, ex);
        }
    }
}

Related

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