怎样对图片base64解码?

youngmean 2005-02-02 05:48:41
BASE64Decoder decoder = new BASE64Decoder();
File f = new File("what.gif");
FileOutputStream fos = new FileOutputStream(f);
byte[] buf = decoder.decodeBuffer(strBase64);
fos.write(buf);
fos.close();

不行呀!!怎么做?????
...全文
527 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yyil80 2010-06-23
  • 打赏
  • 举报
回复
学习了。
GJA106 2005-02-03
  • 打赏
  • 举报
回复
编码代码:
FileInputStream fileForInput = new FileInputStream("c:\\test.gif");
String content = new String();
byte[] bytes = new byte[fileForInput.available()];
fileForInput.read(bytes);
content = new sun.misc.BASE64Encoder().encode(bytes); //具体的编码方法
fileForInput.close();

解码代码:

str = "";//编码内容
byte[] result =new sun.misc.BASE64Decoder().decodeBuffer(str.trim());
RandomAccessFile inOut = new RandomAccessFile("c:\\my.jpg","rw");
inOut.write(result);
inOut.close();
youngmean 2005-02-02
  • 打赏
  • 举报
回复
这样好像有问题ya!:
public static String base64Decode(String base64Src){
String r = "";
try{
BASE64Decoder decoder = new BASE64Decoder();
byte[] buf = decoder.decodeBuffer(base64Src);
r = new String(buf);
}catch(Exception e){
e.printStackTrace();
}
return r;
}
GJA106 2005-02-02
  • 打赏
  • 举报
回复
如果what.gif是在当前jvm默认路径下File f = new File("what.gif");就起作用,否则使用绝对路径来完成文件定位。如:File f = new File("d:\\images\\what.gif");
youngmean 2005-02-02
  • 打赏
  • 举报
回复
what.gif打不开

50,530

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧