博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java上传图片损坏_大神求助 上传图片后 图片损坏
阅读量:1539 次
发布时间:2019-04-21

本文共 1117 字,大约阅读时间需要 3 分钟。

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

Map dataMap = new HashMap();

String filepath="D:/tou.jpg";

BASE64Decoder decoder = new BASE64Decoder();

try {

byte[] b = decoder.decodeBuffer(filepath);

for(int i=0;i

if(b[i]<0) {//调整异常数据

b[i]+=256;

}

}

//生成图片

File imgFile=new File(filepath);

String fileExt = imgFile.getName().substring(

imgFile.getName().lastIndexOf(".") + 1).toLowerCase();

SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");

String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000)+"."+fileExt;

String savePath= getRequest().getServletContext().getRealPath("/upload/appImg/");

File dirFile = new File(savePath);

if (!dirFile.exists()) {

dirFile.mkdirs();

}

String imgFilePath = getRequest().getServletContext().getRealPath("/upload/appImg")+"/" +newFileName;//新生成的图片

String url="/upload/appImg/"+newFileName;

OutputStream out = new FileOutputStream(imgFilePath);

out.write(b);

out.flush();

out.close();

dataMap.put("success", "上传成功");

dataMap.put("url",url);

ReturnJson.goBack(dataMap);

}catch (IOException e) {

dataMap.put("error", "上传失败");

ReturnJson.goBack(dataMap);

e.printStackTrace();

}

转载地址:http://nlldy.baihongyu.com/

你可能感兴趣的文章
OpenBTS教程
查看>>
gr-ieee802-11 源码分析
查看>>
python安装包问题汇总
查看>>
射频指纹识别(RF指纹识别)
查看>>
WiFi 2.4GHz和5GHz的差别
查看>>
linux内核源代码情景分析(第一章 预备知识)
查看>>
linux内核源代码情景分析(第二章 存储管理)
查看>>
linux内核源代码情景分析(第三章 中断、异常和系统调用)
查看>>
linux内核源代码情景分析(第四章 进程和进程调度)
查看>>
linux内核源代码情景分析(第五章 文件系统)
查看>>
linux内核源代码情景分析(第六章 传统unix进程间通信)
查看>>
linux内核源代码情景分析(第七章 基于socket的进程间通信)
查看>>
linux内核源代码情景分析(第八章 设备驱动)
查看>>
linux内核源代码情景分析(第九章 多处理器SMP系统结构)
查看>>
linux内核源代码情景分析(第十章 系统的引导和初始化)
查看>>
低功耗蓝牙开发权威指南--第一部分 综述 (第1-4章)
查看>>
低功耗蓝牙开发权威指南--第二部分控制器(第5-8章)
查看>>
低功耗蓝牙开发权威指南--第三部分 主机 (第9-12章)
查看>>
低功耗蓝牙开发权威指南--第四部分 应用 (第13-15章)
查看>>
gr-bluetooth/libbtbb源码分析
查看>>