/**
* @Author L_derek
* @param base64String base64字符串
* @param filePath 文件存放路径
* @param fileName 文件名
* @return File
*/
public static File base64ToFile(String base64String ,String filePath ,String fileName){
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try{
File file = new File(filePath);
//判断目录是否存在
if (file.exists()&&file.isDirectory()){
file.mkdirs();
}
BASE64Decoder decoder = new BASE64Decoder();
byte[] fileByte = decoder.decodeBuffer(base64String);
String path = filePath + fileName;
file = new File(path);
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(fileByte);
return file;
} catch (IOException e) {
e.printStackTrace();
return null;
}finally {
if (bos != null){
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null){
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
base64转码图片
最新推荐文章于 2024-05-31 09:05:13 发布