压缩包上传及解压
来源:互联网 发布:小米5怎么卸载软件 编辑:程序博客网 时间:2024/06/05 00:35
public final class FileUtil{<span style="white-space:pre"></span>/* * 解压zip包 * zipPath:解压包路径 * descDir:压缩指定位置 * */public static void decompressionZIP(File zipPath,String descDir) throws IOException{ File pathFile = new File(descDir); if(!pathFile.exists()){ pathFile.mkdirs(); } ZipFile zip = new ZipFile(zipPath,"GBK"); for(Enumeration entries = zip.getEntries();entries.hasMoreElements();){ ZipEntry entry = (ZipEntry)entries.nextElement(); String zipEntryName = entry.getName(); InputStream in = zip.getInputStream(entry); String outPath = (descDir+"/"+zipEntryName).replaceAll("\\*", "/");; //判断路径是否存在,不存在则创建文件路径 File file = new File(outPath.substring(0, outPath.lastIndexOf('/'))); if(!file.exists()){ file.mkdirs(); } //判断文件全路径是否为文件夹,如果是上面已经上传,不需要解压 if(new File(outPath).isDirectory()){ continue; } OutputStream out = new FileOutputStream(outPath); byte[] buf1 = new byte[1024]; int len; while((len=in.read(buf1))>0){ out.write(buf1,0,len); } in.close(); out.close(); } }/* * 上传压缩包 * */public static File uploadZip(MultipartFile multifile, File outputPath) throws IOException{ if (!outputPath.exists()) { outputPath.mkdir(); } // 读取文件流并保持在指定路径 InputStream inputStream = multifile.getInputStream(); String output = outputPath.getPath() + "/"+multifile.getOriginalFilename(); OutputStream outputStream = new FileOutputStream(output); byte[] buffer = multifile.getBytes(); int byteread = 0; while ((byteread = inputStream.read(buffer)) != -1) { outputStream.write(buffer, 0, byteread); outputStream.flush(); } outputStream.close(); inputStream.close(); return new File(output);}}
SpringMVC配置
<!-- 文件上传 --><bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"></bean>
@RequestMapping("/upload")public String upload( @RequestParam("file") MultipartFile multifile){ // 创建目录 <span style="white-space:pre"></span>try {cnmlService.persisted(multifile);} catch (Exception e) {}return "suc";}
0 0
- 压缩包上传及解压
- 上传压缩包并解压
- springMVC 上传压缩包文件、解压
- 文件上传压缩包并解压
- 打tar包以及压缩及解压
- Java下载网络压缩包及解压
- PHP上传RAR压缩包并解压类
- php实现上传压缩包后自动解压
- PHP上传RAR压缩包并解压到目录
- 常用压缩包解压
- Python 解压压缩包
- 各种格式tar包解压及压缩 (转)
- 压缩及解压
- 文件上传、压缩解压 操作
- 文件下载,上传,压缩,解压
- linux文件包压缩解压
- 解压“加密”压缩包办法
- 解压zip压缩包(JAVA)
- codeforces568C. New Language
- Android菜鸟笔记- 获取未安装的APK图标、版本、包名、名称、是否安装、安装、打开
- 常见UTF-8和GBK的区别
- 如何提高NodeJS程序的稳定性
- 傅里叶变换
- 压缩包上传及解压
- js开发过程中遇到的一些问题
- 简单排序——冒泡,选择,插入
- Android中Service(服务)详解
- 软件缺陷(defect)和bug的严重性(Severity)和优先级(Priority)
- 【软考之路】软件开发模型
- ym——Android快速开发框架(持续更新!)
- 用筛法求之N内的素数。
- 基数排序