首页 > 技术文章 > java如何使用base64生成图片文件

YuyuanNo1 2018-09-21 09:55 原文

 

 

import org.apache.commons.codec.binary.Base64;
public static void decodeFile(String base64Str,File file) throws Exception {
FileOutputStream write = null;
try {
write = new FileOutputStream(file);
byte[] decoderBytes = Base64.decodeBase64(content.getBytes("UTF-8"));
write.write(decoderBytes);

} catch (Exception e) {
e.printStackTrace();
throw e;
}finally {
try {
if(write!=null)write.flush();
if(write!=null)write.close();
} catch (IOException e) {
e.printStackTrace();
}
}

}

推荐阅读