java如何使用base64生成图片文件

 

 

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();
}
}

}

posted on 2018-09-21 09:55  小甜瓜安东泥  阅读(2066)  评论(0编辑  收藏  举报