Encode binary data as Base64 string
import org.apache.commons.codec.binary.Base64; import java.util.Arrays; public class Base64Encode { public static void main(String[] args) { String hello = "Hello World"; byte[] encoded = Base64.encodeBase64(hello.getBytes()); System.out.println(Arrays.toString(encoded)); String encodedString = new String(encoded); System.out.println(hello + " = " + encodedString); } }