package com.winsun.utils;

import com.winsun.auth.core.common.model.ResponseData;
import com.winsun.auth.core.util.IOUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.multipart.MultipartFile;

import java.io.*;

/**
 * @Author xuede
 * @Date 2020/3/6 10:29
 * @Version 1.0
 */
@Slf4j
public class FileUtil {

    //写到相应路径
    public  static boolean makefile(String path, MultipartFile file,String filename){
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File savePath = new File(dir, filename);
        OutputStream os = null;
        try {
            os = new FileOutputStream(savePath);
            os.write(file.getBytes());
            os.flush();
        } catch (IOException e) {
            log.error("上传文件失败：" + e.getMessage(), e);
            return false;
        } finally {
            IOUtils.closeQuite(os);
        }
        return true;
    }

    public  static boolean makefile1(String path, MultipartFile file,String filename){
        File dir = new File(path);
        if (!dir.exists()) {
            dir.mkdirs();
        }
        File savePath = new File(dir, filename);
        OutputStream os = null;
        try {
            os = new FileOutputStream(savePath);
            os.write(file.getBytes());
            os.flush();
        } catch (IOException e) {
            log.error("上传文件失败：" + e.getMessage(), e);
            return false;
        } finally {
            IOUtils.closeQuite(os);
        }
        return true;
    }
}
