Answers for "save base64 string to image java"

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"

Java Answers by Framework

Browse Popular Code Answers by Language