package com.sysu.admin.utils.file;

import org.springframework.web.multipart.MultipartFile;
import java.io.File;

/**
 * 文件处理工具类
 */
public class FileUtil {

    /**
     * 保存图片
     * @param file
     */
    public static File saveImage(MultipartFile file,String dirPath, String newName){
        if(file == null)
            return null;

        File dir = new File(dirPath);
        if(!dir.exists()) {
            dir.mkdir();
        }
        File image = new File(dir, newName);
        try {
            file.transferTo(image);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return image;
    }
}
