package com.tv.ui.metro.utils; import java.io.UnsupportedEncodingException;import java.nio.ByteBuffer;import java.nio.CharBuffer;import java.nio.charset.Charset; /** * Created by Administrator on 16-3-31. */public class DataUtil { public static char[] getChars(byte[] bytes) { Charset cs = Charset.forName("GBK"); ByteBuffer bb = ByteBuffer.allocate(bytes.length); bb.put(bytes); bb.flip(); CharBuffer cb = cs.decode(bb); return cb.array(); } public static char[] convertBtoC(byte[] bytes) { char[] r = new char[0]; try { r = new String(bytes, 0, bytes.length, "GBK").toCharArray(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } finally { return r; } }}
时间: 2024-08-11 03:30:33