Back
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.
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);
import java.util.Base64;
byte[] bytes = "Hello, World!".getBytes("UTF-8");
String encoded = Base64.getEncoder().encodeToString(bytes);
byte[] decoded = Base64.getDecoder().decode(encoded);
31k questions
32.8k answers
501 comments
693 users