/**
* Base64解码成File文件
*/
public static void base64ToFile(String base64, String fileName, String filePath) {
File file = null;
//创建文件目录
File dir = new File(filePath);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
BufferedOutputStream bos = null;
FileOutputStream fos = null;
byte[] bytes = Base64.getDecoder().decode(base64);
file = new File(filePath + "\\" + fileName);
try {
fos = new FileOutputStream(file);
bos = new BufferedOutputStream(fos);
bos.write(bytes);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (bos != null) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fos != null) {
try {
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Base64解码成File文件
最新推荐文章于 2024-01-30 19:45:13 发布