| | |
| | | package com.whyc.util; |
| | | |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.*; |
| | | import java.net.URLEncoder; |
| | |
| | | } |
| | | } |
| | | |
| | | public static String saveFile(MultipartFile multipartFile,String fileName) throws IOException { |
| | | String rootFile = CommonUtil.getRootFile(); |
| | | |
| | | String filePath = rootFile + fileName; |
| | | File file = new File(filePath); |
| | | File parentFile = file.getParentFile(); |
| | | if(!parentFile.exists()){ |
| | | parentFile.mkdirs(); |
| | | } |
| | | //存储 |
| | | multipartFile.transferTo(file); |
| | | |
| | | return "doc_file"+fileName; |
| | | } |
| | | |
| | | /** |
| | | * 复制文件夹内的所有文件到另一个文件夹 |
| | | */ |
| | | public static void copyDirectory(File source, File destination) { |
| | | if (source.isDirectory()) { |
| | | if (!destination.exists()) { |
| | | destination.mkdir(); |
| | | } |
| | | for (File file : source.listFiles()) { |
| | | copyDirectory(file, new File(destination, file.getName())); |
| | | } |
| | | } else { |
| | | try (FileInputStream inputStream = new FileInputStream(source); |
| | | FileOutputStream outputStream = new FileOutputStream(destination)) { |
| | | byte[] buffer = new byte[1024]; |
| | | int length; |
| | | while ((length = inputStream.read(buffer)) > 0) { |
| | | outputStream.write(buffer, 0, length); |
| | | } |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207泰州平台"); |
| | | List list = new ArrayList<>(); |