关于byte[]和字符串的转换

    public static String byteToStr(byte[] b) {
        return Arrays.toString(b);
    }

    public static byte[] strToByte(String str) {
        return str.getBytes();
    }

 

还有一种byte[]转String的方法是:

    public static String byteToStr(byte[] b) {
        return new String(b);
    }

 

但是这种方法,想要输出byte[],也要以形式 str.getBytes()[0]   ;  str.getBytes()[1] 的形式 ,不能直接输出 str.getBytes();

 

posted on 2017-08-23 16:34  斜月三星一太阳  阅读(554)  评论(0编辑  收藏  举报