• Home
  • LLMs
  • Python
  • Docker
  • Kubernetes
  • Java
  • Maven
  • All
  • About
Java | Base64
  1. Encode/Decode

  1. Encode/Decode
    import java.io.UnsupportedEncodingException;
    import java.util.Base64;
    
    public class Base64Test {
        public static void main(String[] args) throws UnsupportedEncodingException {
            final String value = "test";
    
            final byte[] encodedValue = Base64.getEncoder().encode(value.getBytes("UTF-8"));
    
            final byte[] decodedValue = Base64.getDecoder().decode(encodedValue);
    
            // should print 'test'!
            System.out.println(new String(decodedValue, "UTF-8"));
        }
    }
© 2025  mtitek