Here you can find the source of getBytesFromText(String text, String charset)
Parameter | Description |
---|---|
text | The text to be converted. |
charset | The charset to be used for converting. |
public static final byte[] getBytesFromText(String text, String charset)
//package com.java2s; /*/*from w ww . j av a 2s . c om*/ * This Source Code Form is subject to the terms of the * Mozilla Public License, v. 2.0. * If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.io.UnsupportedEncodingException; public class Main { /** * Converts a text into a byte array using the given charset, if possible. * * @param text The text to be converted. * @param charset The charset to be used for converting. * @return */ public static final byte[] getBytesFromText(String text, String charset) { try { return text.getBytes(charset); } catch (UnsupportedEncodingException e) { } return text.getBytes(); } }