Here you can find the source of getUTF8String(byte[] bytes)
Parameter | Description |
---|---|
bytes | the <tt>byte</tt> array that we'd like to convert into a <tt>String</tt>. |
public static String getUTF8String(byte[] bytes)
//package com.java2s; /*// w w w . j a v a2 s . co m * 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 { /** * Converts <tt>string</tt> into an UTF8 <tt>String</tt> and handles the * unlikely case where UTF-8 is not supported. * * @param bytes the <tt>byte</tt> array that we'd like to convert into a * <tt>String</tt>. * * @return the UTF-8 <tt>String</tt>. */ public static String getUTF8String(byte[] bytes) { try { return new String(bytes, "UTF-8"); } catch (UnsupportedEncodingException exc) { // shouldn't happen. UTF-8 is always supported, anyways ... if //this happens, we'll cheat return new String(bytes); } } }