Decodes a String to Base64 - Java java.lang

Java examples for java.lang:String Base64

Description

Decodes a String to Base64

Demo Code


//package com.java2s;
import java.nio.charset.StandardCharsets;

public class Main {
    public static void main(String[] argv) throws Exception {
        String stringToDecode = "java2s.com";
        System.out.println(decode(stringToDecode));
    }//from w  w w . j  a  v  a  2s . c  o  m

    /**
     * Decodes a String to Base64
     * @param stringToDecode The String to be encoded
     * @return The Base64 encoded String
     */
    public static String decode(String stringToDecode) {
        return new String(java.util.Base64.getDecoder().decode(
                stringToDecode), StandardCharsets.UTF_8);
    }
}

Related Tutorials