java:image to base64 string example
Example: java:image to base64 string example
public static void main(String[] args) throws Exception{
File f = new File("/opt/myImage.jpg");
String encodstring = encodeFileToBase64Binary(f);
System.out.println(encodstring);
}
private static String encodeFileToBase64Binary(File file) throws Exception{
FileInputStream fileInputStreamReader = new FileInputStream(file);
byte[] bytes = new byte[(int)file.length()];
fileInputStreamReader.read(bytes);
return new String(Base64.encodeBase64(bytes), "UTF-8");
}