如题
package com.zm.baidu_face.util; import sun.misc.BASE64Encoder; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class ImageUtils { static BASE64Encoder encoder = new BASE64Encoder(); public static String image2Base64(String imageFilePath) throws IOException { FileInputStream fis = new FileInputStream(new File(imageFilePath)); byte[] bytes = new byte[fis.available()]; fis.read(bytes); String base64String = encoder.encode(bytes); // System.out.println("base64String: " + base64String); return base64String; } public static void main(String[] args) throws IOException { image2Base64("D://test.jpg"); } }