Answers for "java:image to base64 string example"

0

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");
        }
Posted by: Guest on June-10-2021

Code answers related to "java:image to base64 string example"

Browse Popular Code Answers by Language