1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
| package com.moral.util;
|
| import org.springframework.web.multipart.MultipartFile;
|
| import java.io.File;
|
| public class FileUtils {
|
| /**
| * @param file 文件
| * @param path 文件存放路径
| * @param fileName 保存的文件名
| * @return
| */
| public static boolean upload(MultipartFile file, String path, String fileName) {
| //确定上传的文件名
| String realPath = path + File.separator + fileName;
| File dic = new File(path);
|
| if (!dic.exists()) {
| dic.mkdirs();
| }
|
| try {
| //保存文件
| file.transferTo(new File(realPath));
| return true;
| } catch (Exception e) {
| e.printStackTrace();
| return false;
| }
| }
| }
|
|