mirror of https://github.com/elunez/eladmin
Merge remote-tracking branch 'origin/master'
# Conflicts: # eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.javapull/174/head
commit
5916cb2f50
|
@ -7,7 +7,6 @@ import cn.hutool.poi.excel.BigExcelWriter;
|
||||||
import cn.hutool.poi.excel.ExcelUtil;
|
import cn.hutool.poi.excel.ExcelUtil;
|
||||||
import me.zhengjie.exception.BadRequestException;
|
import me.zhengjie.exception.BadRequestException;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
@ -20,7 +19,6 @@ import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File工具类,扩展 hutool 工具包
|
* File工具类,扩展 hutool 工具包
|
||||||
*
|
|
||||||
* @author Zheng Jie
|
* @author Zheng Jie
|
||||||
* @date 2018-12-27
|
* @date 2018-12-27
|
||||||
*/
|
*/
|
||||||
|
@ -46,7 +44,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MultipartFile转File
|
* MultipartFile转File
|
||||||
*
|
|
||||||
* @param multipartFile
|
* @param multipartFile
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -69,7 +66,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除
|
* 删除
|
||||||
*
|
|
||||||
* @param files
|
* @param files
|
||||||
*/
|
*/
|
||||||
public static void deleteFile(File... files) {
|
public static void deleteFile(File... files) {
|
||||||
|
@ -82,7 +78,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取文件扩展名
|
* 获取文件扩展名
|
||||||
*
|
|
||||||
* @param filename
|
* @param filename
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -98,7 +93,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Java文件操作 获取不带扩展名的文件名
|
* Java文件操作 获取不带扩展名的文件名
|
||||||
*
|
|
||||||
* @param filename
|
* @param filename
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -114,7 +108,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件大小转换
|
* 文件大小转换
|
||||||
*
|
|
||||||
* @param size
|
* @param size
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
|
@ -137,14 +130,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputStream 转 File
|
* inputStream 转 File
|
||||||
*
|
|
||||||
* @param ins
|
* @param ins
|
||||||
* @param name
|
* @param name
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public static File inputStreamToFile(InputStream ins, String name) throws Exception{
|
public static File inputStreamToFile(InputStream ins, String name) throws Exception{
|
||||||
File file = new File(System.getProperty("java.io.tmpdir") + name);
|
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + name);
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
@ -174,12 +166,13 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
String nowStr = "-" + format.format(date);
|
String nowStr = "-" + format.format(date);
|
||||||
try {
|
try {
|
||||||
String fileName = name + nowStr + "." + suffix;
|
String fileName = name + nowStr + "." + suffix;
|
||||||
String path = filePath + File.separator + fileName;
|
String path = filePath + fileName;
|
||||||
File dest = new File(path).getCanonicalFile();
|
File dest = new File(path);
|
||||||
// 检测是否存在目录
|
// 检测是否存在目录
|
||||||
if (!dest.getParentFile().exists()) {
|
if (!dest.getParentFile().exists()) {
|
||||||
dest.getParentFile().mkdirs();// 新建文件夹
|
dest.getParentFile().mkdirs();// 新建文件夹
|
||||||
}
|
}
|
||||||
|
String d = dest.getPath();
|
||||||
file.transferTo(dest);// 文件写入
|
file.transferTo(dest);// 文件写入
|
||||||
return dest;
|
return dest;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -201,7 +194,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出excel
|
* 导出excel
|
||||||
*
|
|
||||||
* @param list
|
* @param list
|
||||||
* @return
|
* @return
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
|
@ -244,7 +236,6 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||||
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
|
String mimeType = new MimetypesFileTypeMap().getContentType("." + type);
|
||||||
return mimeType.split("\\/")[0];
|
return mimeType.split("\\/")[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void checkSize(long maxSize, long size) {
|
public static void checkSize(long maxSize, long size) {
|
||||||
if(size > (maxSize * 1024 * 1024)){
|
if(size > (maxSize * 1024 * 1024)){
|
||||||
throw new BadRequestException("文件超出规定大小");
|
throw new BadRequestException("文件超出规定大小");
|
||||||
|
|
Loading…
Reference in New Issue