0 votes
1 view
in Java by (3.4k points)

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.

1 Answer

0 votes
by (46.1k points)

In Java v6, Java SE ships with JAXB.  You can use javax.xml.bind.DatatypeConverter which has static methods that make this simple. Check out parseBase64Binary() and printBase64Binary().

Here's a sample code:

import java.util.Base64;

byte[] bytes = "Hello, World!".getBytes("UTF-8");

String encoded = Base64.getEncoder().encodeToString(bytes);

byte[] decoded = Base64.getDecoder().decode(encoded);

Related questions

0 votes
1 answer
asked Sep 26, 2019 in Java by Shubham (3.9k points)
0 votes
1 answer
asked Jul 10, 2019 in Java by Anvi (10.2k points)
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...