Java Base64 decode String to byte array

Description

Java Base64 decode String to byte array

import java.util.Arrays;
import java.util.Base64;

public class Main {
  public static void main(String[] argv) throws Exception {
    byte[] array = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };

    String s = Base64.getEncoder().encodeToString(array);

    array = Base64.getDecoder().decode(s);

    System.out.println(Arrays.toString(array));
  }// ww  w .j  a  va  2 s .co m
}



PreviousNext

Related