Java Base64 encode byte array to String

Description

Java Base64 encode byte array to String

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));
  }//from   w  w w  . ja v  a2  s  .  c om
}



PreviousNext

Related