7

Possible Duplicate:
Decode Base64 data in java

I am working on java profile, I want to know , how to convert the base64 string to byte array. could any one please provide code & it will be help fule to me.

1

2 Answers 2

15

You can also use Apache Commons Codec (http://commons.apache.org/codec/)

String example = "SGVsbG8gV29ybGQ="
byte[] decoded = org.apache.commons.codec.binary.Base64.decodeBase64(example .getBytes());
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you buddy. The Java's stock parser was not working for me. This worked. :)
Since Java 8 you can use the built in java.util.Base64.
2
import sun.misc.BASE64Decoder;

BASE64Decoder decoder = new BASE64Decoder();
byte[] imageByte = decoder.decodeBuffer(imageData);

Where imageData is String containing Base64 data.

3 Comments

Where is that BASE64Decoder from?
Your program becomes non-portable because sun.misc package is not part of Java SE API and is not guaranteed to be present in the standard library.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.