Decode Base64 data in Java

前端 未结 20 1521
时光说笑
时光说笑 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条回答
  •  旧时难觅i
    2020-11-21 06:30

    Using Java 8 -

        public static String encodeString(String plainString) {
            return  Base64.getEncoder().encodeToString(plainString.getBytes());
        }
    
        public static String decodeString(String encodedString) {
            byte[] bytes = Base64.getDecoder().decode(encodedString);
            return new String(bytes);
        }
    

提交回复
热议问题