Java byte[] 轉 String的簡單轉換

簡單的將byte[] 還原成了 String 值

[TOC]

代碼:

public class Test0719 {
    public static void main(String[] args) {
        String text = "test";
        byte[] textBytes = text.getBytes();
        String content = byteToString(textBytes);
        System.out.println(textBytes + "\n" + content);
    }

    private static String byteToString(byte[] bytes) {
        if (null == bytes || bytes.length == 0) {
            return "";
        }
        String strContent = "";
        try {
            strContent = new String(bytes, "utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        return strContent;
    }
}

運行結果:

7208373-b6b96e0acc5cf05f.png
運行結果.png
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章