2 回答
TA贡献1853条经验 获得超6个赞
public void base64ToFile(String base64, String pdfName) { FileOutputStream fileOutputStream = null; try { //创建文件目录 String filePath="D:\\image"; File file=new File(filePath); if (!file.exists() && !file.isDirectory()) { file.mkdirs(); } byte[] s = Base64.decodeBase64(base64.getBytes()); fileOutputStream = new FileOutputStream(file+File.separator+pdfName); fileOutputStream.write(s); } catch (Exception e) { e.printStackTrace(); } finally { try { fileOutputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
TA贡献1847条经验 获得超11个赞
BASE64解码成File文件
public static void base64ToFile(String base64, String fileName) {
File file = null;
//创建文件目录
String filePath="D:\image";
File dir=new File(filePath);
if (!dir.exists() && !dir.isDirectory()) {
dir.mkdirs();
}
BufferedOutputStream bos = null;
java.io.FileOutputStream fos = null;
try {
byte[] bytes = Base64.getDecoder().decode(base64);
file=new File(filePath+"\"+fileName);
fos = new java.io.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();
}
}
}
}
- 2 回答
- 0 关注
- 558 浏览
添加回答
举报