**
图片转base64
**
/**
* 图片转BASE64
*
* @param imagePath 路径
* @return
*/
public String imageChangeBase64(String imagePath) {
InputStream inputStream = null;
byte[] data = null;
try {
inputStream = new FileInputStream(imagePath);
data = new byte[inputStream.available()];
inputStream.read(data);
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
// 加密
//这是jdk1.7
// BASE64Encoder encoder = new BASE64Encoder();
//这是jdk1.8
Base64.Encoder encoder = Base64.getEncoder();
String encode = encoder.encodeToString(data);
return encode;
// return encoder.encode(data);
}
}