图片转base64文字

图片转文字:

File file=new File(s);
FileInputStream fis=null;
String IO="";
StringBuffer sb=new StringBuffer();
byte[] data = null;
try {
fis = new FileInputStream(file);
data = new byte[fis.available()];
fis.read(data);
fis.close();
BASE64Encoder encoder = new BASE64Encoder();
IO=encoder.encodeBuffer(data);
// IO=encoder.encode(data);

//转码后第一次走到这行正常,但是第二次走就会跳到异常里去
sb.append(IO);


System.out.println(999999);
sb.append("\n=====end=====");
System.out.println(sb.toString());
IO=sb.toString();
System.out.println("向服务器傳輸中");
resp.setBody(IO);
System.out.println("傳輸完畢");

 

2、文字转图片

String path = ""; String filename = ""; File folder = new File(path); if (!folder.exists()) { folder.mkdirs(); } File dest = new File(folder, filename); BASE64Decoder decoder = new BASE64Decoder(); try { FileOutputStream write = new FileOutputStream(dest); // Base64解码 byte[] bytes = decoder.decodeBuffer(base64Str); write.write(bytes); write.close(); } catch (IOException e) { throw new BusinessException("目标文件上传发生异常fileName:" + dest.getName(), e); }

 

 

参考网站:

https://my.oschina.net/KingSirLee/blog/710364

https://www.oschina.net/question/2395099_243234

工具包下载地址:

http://download.csdn.net/detail/u012017115/8439669

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值