public String pathToBase64(String filePath){
try {
File file = new File(filePath);
FileInputStream inputFile = new FileInputStream(file);
byte[] buffer = new byte[(int) file.length()];
inputFile.read(buffer);
inputFile.close();
String encode = new BASE64Encoder().encode(buffer);
return "data:image/png;base64,"+encode;
} catch (IOException e) {
e.printStackTrace();
return e.getMessage();
}
}
文件转base64码
最新推荐文章于 2024-03-18 15:40:43 发布