zip4j

解压文件方法:

    public static void unzipFile(final File sourceFile, final String targetPath) {try {final ZipFile zipFile = new ZipFile(sourceFile);zipFile.setCharset(Charset.forName("GBK"));ZipUtil.log.info("begin unpack zip file:{}", sourceFile);String extractedFile;for (final FileHeader fileHeader : zipFile.getFileHeaders()) {extractedFile = fileHeader.getFileName();// 如果是fileHeader的文件名是utf-8且zipFile的编码不为空且zipFile的编码不是utf-8,则重置zipFile的编码为utf-8if (fileHeader.isFileNameUTF8Encoded() && (zipFile.getCharset() != null)&& !"utf-8".equalsIgnoreCase(zipFile.getCharset().name())) {// 转换文件名extractedFile = new String(extractedFile.getBytes("GBK"), "utf-8");// 重置zipFile的编码zipFile.setCharset(Charset.forName("utf-8"));// 重置fileHeader的文件名fileHeader.setFileName(extractedFile);}if ((zipFile.getCharset() != null) && !"GBK".equalsIgnoreCase(zipFile.getCharset().name())) {zipFile.setCharset(Charset.forName("GBK"));}zipFile.extractFile(fileHeader, targetPath, extractedFile);}ZipUtil.log.info("unpack zip file success");} catch (final Exception e) {e.printStackTrace();throw new RuntimeException("文件解压失败!!");}}

压缩文件方法:(使用输入输出流)

@ApiOperation(value = "电子招标对接,采购、项目和代理机构信息数据导出", notes = "")@RequestMapping(value = "/{projectPurchaseId}/GetPurchaseInfoForEBind", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)//压缩包文件导出public RestDTO<Void> getPurchaseInfoForEBind(@PathVariable final Long projectPurchaseId,HttpServletResponse response) throws UnsupportedEncodingException {ZipOutputStream outputStream = null;OutputStream os;InputStream inputStream = null;CommonPurchaseInfo info = projectPurchaseService.getCommonPurchaseInfoForEbind(projectPurchaseId);String fileName = info.getPurchaseNo();String infos = JSON.toJSONString(info);//TODO 需确定是否可以在file后面加时间区分File file = new File("data.json");try {response.reset();// 清空输出流response.setHeader("content-type", "application/octet-stream");response.setContentType("application/octet-stream");response.setHeader("Content-Disposition","attachment;filename=" + URLEncoder.encode(fileName+".zip", "UTF-8"));// 设定输出文件头//TODO 需确定压缩密码outputStream = new ZipOutputStream(response.getOutputStream(),"password".toCharArray());ZipParameters parameters = new ZipParameters();parameters.setCompressionMethod(CompressionMethod.STORE);parameters.setCompressionLevel(CompressionLevel.NORMAL);parameters.setEncryptFiles(true);parameters.setEncryptionMethod(EncryptionMethod.ZIP_STANDARD);parameters.setAesKeyStrength(AesKeyStrength.KEY_STRENGTH_256);parameters.setFileNameInZip("data.json");if (infos!=null){os=new FileOutputStream(file,true);os.write(infos.getBytes());os.close();}parameters.setEntrySize(file.length());LogUtil.info(CommonPurchaseController.log,"文件生成: "+file.getAbsolutePath().toString());//压缩开始outputStream.putNextEntry(parameters);inputStream = new FileInputStream(file);byte[] readBuff = new byte[4096];int readLen = -1;while ((readLen = inputStream.read(readBuff))!=-1){outputStream.write(readBuff,0,readLen);}outputStream.closeEntry();inputStream.close();} catch (IOException e) {e.printStackTrace();}finally {//删除创建的文件if (file!=null){file.delete();LogUtil.info(CommonPurchaseController.log,"文件已删除: "+file.getAbsolutePath().toString());}if (outputStream!=null){try {outputStream.close();} catch (IOException e) {e.printStackTrace();}}if (inputStream!=null){try {inputStream.close();} catch (IOException e) {e.printStackTrace();}}}return RestDTO.success();}

文件操作

MultipartFile 保存为文件

           String fileName = multipartFile.getOriginalFilename();File file = new File(fileName);OutputStream out = null;try {out = new FileOutputStream(file);byte[] ss = multipartFile.getBytes();for (int i = 0; i < ss.length; i++) {out.write(ss[i]);}} catch (FileNotFoundException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();} finally {if (out != null) {try {out.close();} catch (IOException e) {e.printStackTrace();}}}

json文件转换为object

FileInputStream fileInputStream = null;
StringBuffer infoString = new StringBuffer("");
try {int len = 0;FileInputStream is = new FileInputStream(targetPath + "data.json");InputStreamReader isr = new InputStreamReader(is);BufferedReader in = new BufferedReader(isr);String line = null;while ((line = in.readLine()) != null) {// 处理换行符的问题if (len != 0) {infoString.append("\r\n" + line);} else {infoString.append(line);}len++;}in.close();is.close();

异步任务(使用Reacotr)

使用

        BaseReactor.notifyEvent(eventBus,"ebindUploadRecordFiles",fileUploadBean);

consumer

    @Overridepublic void afterPropertiesSet() throws Exception {this.on(this.eventBus,"ebindUploadRecordFiles",this);}@Overridepublic void onEvent(CurrentUserDetailsBean bean,FileUploadBean fileUploadBean) {...}

电子招标项目代码笔记相关推荐

  1. 基于GEC6818的智能家居系统[完整源码/项目报告/笔记分享]

    基于GEC6818的智能家居系统 项目目标: 使用GEC6818(ARM开发板)以及Linux操作系统来设计一个可以实现动感相册/监控/音乐播放器功能且UI友好,人机交互性高的智能家居系统. 代码编写 ...

  2. 开源电子商城系统:罗列几个电子商城系统,和一个不错的开源电子商城项目:mall,先做技术调研,主要还是学习代码。

    目录 前言 1,关于电子商城 2,偶然发现了 xmall 项目 3,其他资源 4,GitEE 上面还有一堆 5,总结 前言 本文的原文连接是: https://blog.csdn.net/freewe ...

  3. JavaWeb黑马旅游网-学习笔记10【项目代码】

    Java后端 学习路线 笔记汇总表[黑马程序员] JavaWeb黑马旅游网-学习笔记01[准备工作] JavaWeb黑马旅游网-学习笔记02[注册功能] JavaWeb黑马旅游网-学习笔记03[登陆和 ...

  4. java版本+企业电子招标采购系统源码+项目模块功能清单+spring cloud +spring boot

    项目说明 随着公司的快速发展,企业人员和经营规模不断壮大,公司对内部招采管理的提升提出了更高的要求.在企业里建立一个公平.公开.公正的采购环境,最大限度控制采购成本至关重要.符合国家电子招投标法律法规 ...

  5. 【报错笔记】在做struts项目时,所有项目代码没问题但就是报404错误。

    在做struts项目时,所有项目代码没问题但就是报404错误,而且tomcat一次只能运行一个项目,做第二个得关闭tomcat,清空再开启运行. 我重新下载了tomcat9还是那样,可能是eclips ...

  6. 电子招标采购平台源码php,电子招投标平台_企业招标管理系统_招标采购管理软件-高亚科技8manage SRM...

    8Manage 电子招标 8Manage 电子招投标平台为企业的招投标提供高效,公平和全面有力的监控.企业可按需预先设定招投标的规则,整个招投标过程系统都会严格遵循这些规则执行.另外,8Manage ...

  7. CSDN技术主题月----“深度学习”代码笔记专栏

    from: CSDN技术主题月----"深度学习"代码笔记专栏 2016-09-13 nigelyq 技术专题 Hi,各位用户 CSDN技术主题月代码笔记专栏会每月在CODE博客为 ...

  8. Unity3D项目实战笔记(10):Unity3D编译IPA的PostEvents–节约时间利器

    最近,SDK支付等接入差不多了,就从Unity3D生成IPA (企业版License), 然,需要手动执行的PostEvents竟然多大10项+, 这些我默默的承受了1周时间,每次约浪费20分钟-额外 ...

  9. TheBeerHouse 网站项目学习笔记(5)---架构设计

    前述讨论:    TheBeerHouse 网站项目学习笔记(1)----换肤技术                     TheBeerHouse 网站项目学习笔记(2)----个性化管理      ...

最新文章

  1. 如何从机器学习数据中获取更多收益
  2. python自定义函数和类并调用
  3. python subprocess.Popen 使用简介
  4. PS摩棒工具如何选中自己想要的区域
  5. easyui不同的jsp页面之间混乱_16.jsp九大内置对象,四大作用域
  6. 6.变量的使用.rs
  7. 存储入门:存储区域网络SAN技术完全详解
  8. 接口上加@feignclient还有实现类_类接口的实现及应用
  9. html属于什么数据类型,javascript包括哪些数据类型?
  10. 【hortonworks/registry】registry 如何创建 互相依赖的 schema
  11. ##CSP 201803-2 碰撞的小球(C语言)100分
  12. java 负数异常_java基础之异常
  13. Java 基础 —— Character 与 String
  14. java lc ctype_postgresql中的 LC_CTYPE、LC_COLLATE
  15. 2017百度之星程序设计大赛 - 资格赛
  16. 牛人搜集的常用的资源类网站及68个各类资源网站汇总
  17. fatal: unsafe repository is owned by someone else 的解决方法
  18. 离线调用linux命令,GitHub - rinetd/linux-command: Linux命令大全搜索工具,内容包含Linux命令手册、详解、学习、搜集。...
  19. MYSQL查询优化一
  20. 大华摄像头使用外网接收数据

热门文章

  1. JavaScript 读取Cookie
  2. 将服务器设为禁PING步骤
  3. python---SSH连接linux服务
  4. W3C推荐的标准本体语言,WSDL和XML Schema的语义标注(SWSDL)成为W3C推荐
  5. Linux系统特殊符号总结
  6. 关于ENVI5.1/5.3 软件在辐射定标+大气校正过程中出现的基础问题
  7. MySQL创建函数报“ERROR 1418 ”错误,不能创建函数
  8. 决策树准确率低原因_新上市酸奶决策树分析
  9. lsof命令简单使用
  10. 【AHK】如何获取前一个窗口的exe信息