分享一个FileUtil工具类,基本满足web开发中的文件上传,单个文件下载,多个文件下载的需求

获取该FileUtil工具类源码,公众号内回复fileutil20200501即可。

1.文件上传方法

uploadFile(String filePath, InputStream inputStream);

参数解释

filePath:上传文件存储的路径

inputStream:上传文件的文件输入流,从MultipartFile对象中,通过getInputStream();方法即可获取。

2.单个文件下载方法

downloadFile(String fileName,String filePath, HttpServletResponse response) throws Exception

参数解释

fileName:下载后文件的文件名

filePath:下载文件在服务器的路径位置

response:响应体

3.多个文件下载方法

downLoadFiles(String zipFileName, List<File> fileList, HttpServletResponse response) throws Exception

参数解释

zipFileName:下载后压缩包的文件名

fileList:多个文件组成的集合

response:响应体