Here you can find the source of getUTF8Bytes(String string)
Parameter | Description |
---|---|
string | the <tt>String</tt> whose bytes we'd like to obtain. |
public static byte[] getUTF8Bytes(String string)
//package com.java2s; /*//from w w w .jav a 2 s . c om * Jitsi, the OpenSource Java VoIP and Instant Messaging client. * * Distributable under LGPL license. * See terms of license at gnu.org. */ import java.io.*; public class Main { /** * Returns the UTF8 bytes for <tt>string</tt> and handles the unlikely case * where UTF-8 is not supported. * * @param string the <tt>String</tt> whose bytes we'd like to obtain. * * @return <tt>string</tt>'s bytes. */ public static byte[] getUTF8Bytes(String string) { try { return string.getBytes("UTF-8"); } catch (UnsupportedEncodingException exc) { // shouldn't happen. UTF-8 is always supported, anyways ... if //this happens, we'll cheat return string.getBytes(); } } }