modify
This commit is contained in:
parent
47d65ac6b3
commit
af975f5eb1
@ -744,41 +744,53 @@ public class FileController {
|
||||
package com.heibaiying.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
* @description : 文件上传工具类
|
||||
*/
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String path) {
|
||||
InputStream inputStream = null;
|
||||
FileOutputStream outputStream = null;
|
||||
String fullPath = path + File.separator + file.getOriginalFilename();
|
||||
try {
|
||||
File saveDir = new File(path);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(new File(fullPath));
|
||||
InputStream inputStream = file.getInputStream();
|
||||
outputStream = new FileOutputStream(new File(fullPath));
|
||||
inputStream = file.getInputStream();
|
||||
byte[] bytes = new byte[1024 * 1024];
|
||||
int read;
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
4.新建用于上传的jsp页面,上传文件时表单必须声明 enctype="multipart/form-data"
|
||||
|
@ -2,34 +2,49 @@ package com.heibaiying.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
* @description : 文件上传工具类
|
||||
*/
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String path) {
|
||||
InputStream inputStream = null;
|
||||
FileOutputStream outputStream = null;
|
||||
String fullPath = path + File.separator + file.getOriginalFilename();
|
||||
try {
|
||||
File saveDir = new File(path);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(new File(fullPath));
|
||||
InputStream inputStream = file.getInputStream();
|
||||
outputStream = new FileOutputStream(new File(fullPath));
|
||||
inputStream = file.getInputStream();
|
||||
byte[] bytes = new byte[1024 * 1024];
|
||||
int read;
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fullPath;
|
||||
}
|
||||
|
@ -735,41 +735,53 @@ public class FileController {
|
||||
package com.heibaiying.utils;
|
||||
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
* @description : 文件上传工具类
|
||||
*/
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String path) {
|
||||
InputStream inputStream = null;
|
||||
FileOutputStream outputStream = null;
|
||||
String fullPath = path + File.separator + file.getOriginalFilename();
|
||||
try {
|
||||
File saveDir = new File(path);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(new File(fullPath));
|
||||
InputStream inputStream = file.getInputStream();
|
||||
outputStream = new FileOutputStream(new File(fullPath));
|
||||
inputStream = file.getInputStream();
|
||||
byte[] bytes = new byte[1024 * 1024];
|
||||
int read;
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fullPath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
4.新建用于上传的jsp页面,上传文件时表单必须声明 enctype="multipart/form-data"
|
||||
|
@ -3,33 +3,48 @@ package com.heibaiying.utils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* @author : heibaiying
|
||||
* @description : 文件上传工具类
|
||||
*/
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static String saveFile(MultipartFile file, String path) {
|
||||
InputStream inputStream = null;
|
||||
FileOutputStream outputStream = null;
|
||||
String fullPath = path + File.separator + file.getOriginalFilename();
|
||||
try {
|
||||
File saveDir = new File(path);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.mkdirs();
|
||||
}
|
||||
FileOutputStream outputStream = new FileOutputStream(new File(fullPath));
|
||||
InputStream inputStream = file.getInputStream();
|
||||
outputStream = new FileOutputStream(new File(fullPath));
|
||||
inputStream = file.getInputStream();
|
||||
byte[] bytes = new byte[1024 * 1024];
|
||||
int read;
|
||||
while ((read = inputStream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, read);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (inputStream != null) {
|
||||
try {
|
||||
inputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (outputStream != null) {
|
||||
try {
|
||||
outputStream.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return fullPath;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user