Decode Base64 data in Java

前端 未结 20 1440
时光说笑
时光说笑 2020-11-21 06:04

I have an image that is Base64 encoded. What is the best way to decode that in Java? Hopefully using only the libraries included with Sun Java 6.

20条回答
  •  北海茫月
    2020-11-21 06:40

    This is a late answer, but Joshua Bloch committed his Base64 class (when he was working for Sun, ahem, Oracle) under the java.util.prefs package. This class existed since JDK 1.4.

    E.g.

    String currentString = "Hello World";
    String base64String = java.util.prefs.Base64.byteArrayToBase64(currentString.getBytes("UTF-8"));
    

提交回复
热议问题