收藏点赞不迷路  关注作者有好处

文末获取源码

项目编号:BS-XX-178

一,项目简介

主要使用 gzip协议对上传到服务器的文件进行在线压缩和解压操作。

二,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

三,系统展示

用户登陆

进入指定文件的目录:展示目 录下文件和文件夹列表

在线对文件进行压缩或解压,也可以进行删除操作

四,核心代码展示

package com.sdy.unzipSystem.controllers;import cn.hutool.core.io.FileUtil;
import cn.hutool.core.lang.Console;
import cn.hutool.core.util.StrUtil;
import cn.hutool.core.util.ZipUtil;
import com.sdy.unzipSystem.dto.DirDTO;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;import javax.servlet.http.HttpServletResponse;
import javax.swing.filechooser.FileSystemView;
import java.io.*;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;@Controller
@RequestMapping("file")
public class FileController {@Value("${root.path}")private String rootPath;/*** 上传文件** @param file* @param path* @return*/@RequestMapping("upload")@ResponseBodypublic Map<String, String> upload(@RequestParam("file") MultipartFile file, @RequestParam("path") String path) {// 判断文件是否为空HashMap<String, String> message = new HashMap<>();if (!file.isEmpty()) {try {// 文件保存路径String filePath = path + "/" + file.getOriginalFilename();// 转存文件file.transferTo(new File(filePath));message.put("status", "ok");} catch (Exception e) {
//                e.printStackTrace();message.put("status", "error");}}return message;}/*** 下载** @param response* @param path* @return* @throws Exception*/@RequestMapping(value = "/download")public String downloads(HttpServletResponse response, @RequestParam("path") String path) throws Exception {String fileName = path.split("\\\\")[path.split("\\\\").length - 1];File file = new File(path);response.reset();response.setCharacterEncoding("UTF-8");response.setContentType("multipart/form-data");response.setHeader("Content-Disposition", "attachment;fileName=" + URLEncoder.encode(fileName, "UTF-8"));FileInputStream input = new FileInputStream(file);OutputStream out = response.getOutputStream();byte[] buff = null;buff = new byte[1024];Long size = FileUtil.size(file);if (size >= 1024 * 20) {buff = new byte[1024 * 10];}if (size < 1024 * 20) {buff = new byte[size.intValue()];}if (size == 0) {buff = new byte[50];}int index = 0;while ((index = input.read(buff)) != -1) {out.write(buff, 0, index);out.flush();}out.close();input.close();return null;}/*** 得到系统根路径磁盘列表** @return*/@RequestMapping("getRootFileList")@ResponseBodypublic HashMap getRootFileList() {HashMap<String, Object> rs = new HashMap<>();FileSystemView sys = FileSystemView.getFileSystemView();File[] files = null;if (StrUtil.isNotBlank(rootPath)) {return getFileList(rootPath);}files = File.listRoots();ArrayList<DirDTO> list = new ArrayList<>();for (int i = 0; i < files.length; i++) {System.out.println(files[i] + " -- " + sys.getSystemTypeDescription(files[i]));DirDTO d = new DirDTO();d.setPath(files[i].toString());d.setSimpleName(files[i].toString());d.setType(files[i].isDirectory() ? "dir" : "file");d.setInfo(sys.getSystemTypeDescription(files[i]));if (!FileUtil.isDirectory(files[i])) {String readableSize = FileUtil.readableFileSize(files[i]);if ("0".equals(readableSize) || "".equals(readableSize)) {d.setReadableSize("-");} else {d.setReadableSize(readableSize);}} else {d.setReadableSize("-");}list.add(d);}rs.put("status", "ok");rs.put("rs", list);return rs;}/*** 得到一个目录下的文件列表** @param path* @return*/@RequestMapping("getFileList")@ResponseBodypublic HashMap getFileList(@RequestParam("path") String path) {HashMap<String, Object> rs = new HashMap<>();FileSystemView sys = FileSystemView.getFileSystemView();File root = FileUtil.file(path);root.listFiles();File[] files = root.listFiles();ArrayList<DirDTO> list = new ArrayList<>();for (int i = 0; i < files.length; i++) {System.out.println(files[i] + " -- " + sys.getSystemTypeDescription(files[i]));DirDTO d = new DirDTO();d.setPath(files[i].toString());d.setSimpleName(files[i].getName());d.setType(files[i].isDirectory() ? "dir" : "file");d.setInfo(sys.getSystemTypeDescription(files[i]));if (!FileUtil.isDirectory(files[i])) {String readableSize = FileUtil.readableFileSize(files[i]);if ("0".equals(readableSize) || "".equals(readableSize)) {d.setReadableSize("-");} else {d.setReadableSize(readableSize);}} else {d.setReadableSize("-");}list.add(d);}rs.put("status", "ok");rs.put("rs", list);return rs;}/*** 删除文件** @param path* @return*/@RequestMapping("delFile")@ResponseBodypublic HashMap delFile(@RequestParam("path") String path) {HashMap<String, Object> rs = new HashMap<>();Console.log("删除文件:" + path);FileUtil.del(path);return rs;}/*** 压缩文件或文件夹** @param path* @return*/@RequestMapping("package")@ResponseBodypublic HashMap packagePath(@RequestParam("path") String path) {HashMap<String, Object> rs = new HashMap<>();ZipUtil.zip(path);rs.put("status", "ok");return rs;}/*** 解压缩文件或文件夹** @param path* @return*/@RequestMapping("unPackage")@ResponseBodypublic HashMap unPackage(@RequestParam("path") String path) {HashMap<String, Object> rs = new HashMap<>();if (path.contains(".zip")) {ZipUtil.unzip(path);}rs.put("status", "ok");return rs;}/*** 新建文件夹** @param path* @return*/@RequestMapping("newPackage")@ResponseBodypublic HashMap newPackage(@RequestParam("path") String path, @RequestParam("name") String name) {HashMap<String, Object> rs = new HashMap<>();FileUtil.mkdir(path + "\\" + name);rs.put("status", "ok");return rs;}/*** 删除文件夹** @param path* @return*/@RequestMapping("delDir")@ResponseBodypublic HashMap delDir(@RequestParam("path") String path) {HashMap<String, Object> rs = new HashMap<>();Console.log("删除目录:" + path);FileUtil.del(path);rs.put("status", "ok");return rs;}/*** 复制整个文件和文件夹** @param oldPath* @param newPath* @return*/@ResponseBody@RequestMapping("copyFileOrDir")public HashMap<String, Object> copyFileOrDir(@RequestParam("oldPath") String oldPath, @RequestParam("newPath") String newPath) {HashMap<String, Object> rs = new HashMap<>();FileUtil.copy(oldPath, newPath, true);rs.put("status", "ok");return rs;}/*** 移动整个文件和文件夹** @param oldPath* @param newPath* @return*/@ResponseBody@RequestMapping("rmFileOrDir")public HashMap<String, Object> rmFileOrDir(@RequestParam("oldPath") String oldPath, @RequestParam("newPath") String newPath) {HashMap<String, Object> rs = new HashMap<>();FileUtil.copy(oldPath, newPath, true);FileUtil.del(oldPath);rs.put("status", "ok");return rs;}/*** 修改文件名或目录名** @param path* @param newName* @return*/@ResponseBody@RequestMapping("renameFileOrDir")public HashMap<String, Object> renameFileOrDir(@RequestParam("path") String path, @RequestParam("newName") String newName) {HashMap<String, Object> rs = new HashMap<>();FileUtil.rename(FileUtil.file(path), newName, false, true);rs.put("status", "ok");return rs;}}
package com.sdy.unzipSystem.controllers;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;import javax.servlet.http.HttpServletRequest;@RequestMapping("page")
@Controller
public class PathController {@RequestMapping("/")public String index() {return "/index";}@RequestMapping("login")public String login() {return "login";}@RequestMapping("loginValiData")public String loginValiData(@RequestParam("pass") String pass, HttpServletRequest request){request.getSession().setAttribute("adminpass",pass);return "login";}@RequestMapping("{page}")public String info(@PathVariable("page") String page){return page;}
}

五,项目总结

系统运行完整,界面简洁大方

文件在线压缩与解压|基于Springboot实现文件在线压缩与解压相关推荐

  1. 基于SpringBoot+SSM校园在线打印预约系统设计与实现(附源码论文)-毕业设计

    文章目录 1.适用人群 2.你将收获 3.开发背景 4.开发目的 5.项目简介 6.项目运行截图 1.适用人群 本课程主要是针对计算机专业相关正在做毕业设计或者是需要实战项目的Java开发学习者. 2 ...

  2. 基于springboot的文件上传功能的实现

    基于springboot的文件上传功能的实现: 前言:本人是刚学习java后端不久,所以通过记录一下平时所学知识,方便日后的复习,如果有出错的地方,还望包含. 1.使用的工具是idea,和spring ...

  3. 基于Springboot和mybatis在线考试系统的设计与实现

    基于Springboot和mybatis在线考试系统的设计与实现 源码获取:https://www.bilibili.com/video/BV1Ne4y1g7dC/ 本系统实现了 考试系统的主要功能, ...

  4. 基于 SpringBoot 开发的在线短链生成系统(附源码)

    前言 分享一个基于 SpringBoot 开发的在线短链生成系统,在线短链接生成器. 完整项目源码在文章结尾处,大家自行下载即可~ 一.实现功能 1.将长链接转换成短链接,访问短链接时, 302重定向 ...

  5. 基于springboot的房产在线买房卖房租房管理系统

    基于Springboot的房产在线买房卖房租房管理系统,主要实现了普通用户在线参与买房卖房基本操作流程的全部功能,系统分普通用户.超级管理员(房产中介公司)等角色,除基础脚手架外,实现的功能有: 超级 ...

  6. Java项目-基于Springboot+Vue实现在线音乐网站

    项目编号:BS-PT-049 运行环境: 开发工具:IDEA /ECLIPSE 数据库:MYSQL5.7 JAVA:  JDK1.8 依赖管理:MAVEN 后台开发技术:Springboot+SSM ...

  7. java基于springboot+vue的在线作业提交与批改系统nodejs

    在线作业提交与批改系统基于WEB开发, 本在线作业提交与批改系统是对高校教学管理应用的体现,在学生信息管理,课程信息和作业信息管理方面进行了分析设计和实现.通过在线作业提交与批改系统实现,规范的对作业 ...

  8. 手撸一个基于Springboot的文件管理系统,可用于练手或者毕业设计

    本文首发与Java项目实战网,原来链接:http://www.javaxmsz.com/main/detail?blogId=24 最近有粉丝私信问我,想做一个简单的文件管理系统,想练练手,问我有没有 ...

  9. 基于SpringBoot实现文件上传功能(前端使用postman检查request)

    这周培训中有一天的作业是使用SpringBoot实现文件上传功能,老师的要求是在他搭好的基础上加上文件上传模块和前端上传的部分,spring工程搭好了,老师写的代码比较多,虽然实现了功能,但是不助于对 ...

最新文章

  1. errors'MessageBoxA' : function does not take 1 parameter
  2. Keras中几个重要函数用法
  3. Linux基于expect(tcl)实现shell自动交互
  4. hibernate查询-基本查询
  5. ML二:python批量修改文件名-测试KDTree
  6. 论文浅尝 | 基于属性embeddings的跨图谱实体对齐
  7. python运行命令_对python中执行DOS命令的3种方法总结
  8. 小程序新闻列表页面布局代码_论坛小程序·“我的”页面布局
  9. 《敏捷迭代开发:管理者指南》—第2章2.3节时间箱迭代开发
  10. python3贴吧_python3模拟百度登录并实现百度贴吧签到示例分享(百度贴吧自动签到)...
  11. 人脸识别错误代码437是什么意思_英雄联盟手游unabletologin什么意思?显示unabletologin解决方法[多图]-攻略...
  12. 【BIT数据库实验】openGauss数据库实验二:数据库查询
  13. cpython cython_Cython笔记
  14. FLASH--W25QXX系列存储器
  15. CF794E Choosing Carrot
  16. STM32传感器外设集--语音模块(SYN6288)
  17. ubantu 安装显卡
  18. 杂谈---LZ的编程之路以及十点建议
  19. vscode不会自动生成html,vscode 快速生成html
  20. 本人阅读过的优秀小说、文学作品等优秀书籍推荐

热门文章

  1. android手机沙盒作用,Android手机沙盒
  2. 17下列命令中_哪个命令是java的编译命令?,下列命令中,哪个命令是Java的编译命令?A.java cB.javaC.java docD.applet viewer...
  3. Python网络爬虫(九)快递查询
  4. jsp中c标签的引入
  5. 如何有效问问题(转贴)
  6. Spring——Bean管理-xml方式进行属性注入
  7. Springboot毕设项目海鲜配送管理系统q3m5ujava+VUE+Mybatis+Maven+Mysql+sprnig)
  8. IO口软件模拟IIC
  9. 2020-06-19 云运维linux centos7.2 文件管理基础知识总结
  10. 三菱M80/M800系列数控系统二次开发介绍01-全局介绍