字符串(含中文)转16进制,16进制转字符串(含中文)

字符串(含中文)转16进制

public static byte[] SendS(String str){
        byte[] ok = new byte[0];  
        try {
            ok = str.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return ok;
    }

16进制转字符串(含中文)

public static String getString(byte[] bytes) {
        return getString(bytes, "UTF-8");
    }

public static String getString(byte[] bytes, String charsetName)
   {
        return new String(bytes, Charset.forName(charsetName));
    }

记得编码,解码格式一致

发布了40 篇原创文章 · 获赞 45 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/CGG92/article/details/79571418