zoukankan      html  css  js  c++  java
  • 上传文件工具类

    package com.akb.hfcx.csp.common.util;
    
    import java.io.File;
    import java.io.IOException;
    import java.util.UUID;
    
    import org.springframework.web.multipart.commons.CommonsMultipartFile;
    
    public class SuperUploadFileUtil {
        
        public static String uploadFile(CommonsMultipartFile file, String path) throws IllegalStateException, IOException {
            String url = "";
            if (file != null && file.getSize() > 0) {
                // 文件上传
                String oldFilename = file.getOriginalFilename();
                String newFilename = UUID.randomUUID().toString() + oldFilename.substring(oldFilename.lastIndexOf("."));
                File headImgPath = new File(path);
                if (!headImgPath.exists()) {
                    headImgPath.mkdirs();
                }
                File file2 = new File(path + File.separator + newFilename);
                file.transferTo(file2);
                url = newFilename;
            }
            return url;
        }
        
        public static boolean deleteFile(String fileName) {
            File file = new File(fileName);
            // 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
            if (file.exists() && file.isFile()) {
                if (file.delete()) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
  • 相关阅读:
    浏览器默认样式
    display
    JS中的!=、== 、!==、===的用法和区别。
    getElementsByName
    让DIV的滚动条自动滚动到最底部
    uoj118 【UR #8】赴京赶考
    [MtOI2019]幽灵乐团
    uoj213 【UNR #1】争夺圣杯
    loj6198 谢特
    [CTSC2017]密钥
  • 原文地址:https://www.cnblogs.com/zhengyuanyuan/p/10688175.html
Copyright © 2011-2022 走看看