gpt-3.5-turbo-0613· OpenAI
WildChat-4.8M (AI2)
java decode base64
- User
java decode base64
- Assistant
To decode a Base64 encoded string in Java, you can use the
java.util.Base64class: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 theBase64.getDecoder().decode()method to decode the string into a byte array. Finally, we convert the byte array back to a string using theStringconstructor, and print the decoded string.