public static String imgToBase64(File img) {
InputStream is = null;
byte[] data = null;
try {
is = new FileInputStream(img);
data = new byte[1024];
is.read(data);
} catch(IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
is.close();
}
}
return Base64.encodeBase64String(data);
}
原文:https://www.cnblogs.com/lzy7422/p/14863774.html