【java】java base64編碼與解碼

來源:互聯網
上載者:User

標籤:utf-8   enc   工具類   print   pre   blog   工具   nbsp   href   

參考地址:http://blog.csdn.net/zhou_kapenter/article/details/62890262

要求:JDK1.8+ 使用java原生工具類即可實現

【這裡展示字串轉化為byte[]實現的編碼和解碼  那檔案,例片檔案是怎麼實現編碼進行儲存的呢? 參考:http://www.cnblogs.com/sxdcgaq8080/p/8404404.html】


import java.util.Base64;


final Base64.Decoder decoder = Base64.getDecoder();final Base64.Encoder encoder = Base64.getEncoder();final String text = "字串文字";final byte[] textByte = text.getBytes("UTF-8");//編碼final String encodedText = encoder.encodeToString(textByte);System.out.println(encodedText);//解碼System.out.println(new String(decoder.decode(encodedText), "UTF-8"));

 

【java】java base64編碼與解碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.