Java Base64 Encode
Since Java 1.8 developers can use the Base64.Encoder
class to encode data to Base64. This class provides several methods for encoding byte data to Base64 using algorithms specified in RFC 4648 and RFC 2045. In addition, Java provides the Base64.Decoder
class for decoding Base64 values to byte data.
Example #1 (encode string):
import java.util.Base64;
class Base64Encode {
public static void main(String[] args) {
String str = "guru";
String b64 = Base64.getEncoder().encodeToString(str.getBytes());
System.out.println(b64); //-> "Z3VydQ=="
}
}
Comments (24)
I hope you enjoy this discussion. In any case, I ask you to join it.
I would like to get the java code implementation to convert svg image to base-64.
Can you share the code snippet
I would like to see code which converts svg file to buffered image.
I tried so many ways using batik jars but none is giving right output
Its been a week I am struggling. It will be helpful if you can provide me working sample from svg file to buffered image
Example String :
/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAIQAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAlkZXNjAAAA8AAAAHRyWFlaAAABZAAAABRnWFlaAAABeAAAABRiWFlaAAABjAAAABRyVFJDAAABoAAAAChnV
How can i convert url into Base64 image