Here you can find the source of getBytes(final String data, String charset)
Parameter | Description |
---|---|
data | the string to be encoded |
charset | the desired character encoding |
public static byte[] getBytes(final String data, String charset)
//package com.java2s; import java.io.UnsupportedEncodingException; public class Main { /**//from w w w.j a va2 s . c o m * Converts the specified string to a byte array. If the charset is not * supported the default system charset is used. * * @param data the string to be encoded * @param charset the desired character encoding * @return The resulting byte array. */ public static byte[] getBytes(final String data, String charset) { if (data == null) { throw new IllegalArgumentException("data may not be null"); } if (charset == null || charset.length() == 0) { throw new IllegalArgumentException("charset may not be null or empty"); } try { return data.getBytes(charset); } catch (UnsupportedEncodingException e) { return data.getBytes(); } } }