Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· OpenAIAi2 WildChat-4.8M (AI2)

java decode base64

  1. User

    java decode base64

  2. Assistant

    To decode a Base64 encoded string in Java, you can use the java.util.Base64 class:

    Here is an example:

    import java.util.Base64;
    
    public class Base64DecodeExample {
        public static void main(String[] args) {
            String base64String = "SGVsbG8gV29ybGQh"; // Base64 encoded string
            byte[] decodedBytes = Base64.getDecoder().decode(base64String);
            String decodedString = new String(decodedBytes);
    
            System.out.println("Decoded string: " + decodedString);
        }
    }
    

    In this example, we first define the Base64 encoded string "SGVsbG8gV29ybGQh". Then, we use the Base64.getDecoder().decode() method to decode the string into a byte array. Finally, we convert the byte array back to a string using the String constructor, and print the decoded string.