java后台File与base64之间的转化
/**
* @Description: 将base64编码转为文件
* @param filePath
* @param str
* @return File
*/
public static File base64Str2file(String filePath, String str) {
if (isBlank(filePath) || isBlank(str)) {
return null;
}
byte[] bytes = null;
try {
bytes = new BASE64Decoder().decodeBuffer(str);
} catch (Exception e) {
e.printStackTrace();
}
return bytes2File(filePath, bytes);
}
。。。。。。。
/**
* @Description: 将文件转为base64编码
* @param filePath
* @param str
* @return File
*/
public static String file2Base64Str(String filePath) {
byte[] fileBytes = file2Bytes(filePath);
String fileStr = null; // 文件base64位字符串
if (fileBytes != null) {
fileStr = new BASE64Encoder().encode(fileBytes);
}
return fileStr;
}
。。。。。。