西宫硝子|

西宫结弦

园龄:3年2个月粉丝:1关注:1

MultipartFile工具类使用

package org.springframework.web.multipart;

        import java.io.File;
        import java.io.IOException;
        import java.io.InputStream;
        import java.nio.file.Files;
        import java.nio.file.Path;
        import org.springframework.core.io.InputStreamSource;
        import org.springframework.core.io.Resource;
        import org.springframework.lang.Nullable;
        import org.springframework.util.FileCopyUtils;

public interface MultipartFile extends InputStreamSource {
    //getName() 返回参数的名称
    String getName();
    //获取源文件的昵称
    @Nullable
    String getOriginalFilename();
    //getContentType() 返回文件的内容类型
    @Nullable
    String getContentType();
    //isEmpty() 判断是否为空,或者上传的文件是否有内容
    boolean isEmpty();
    //getSize() 返回文件大小 以字节为单位
    long getSize();
    //getBytes() 将文件内容转化成一个byte[] 返回
    byte[] getBytes() throws IOException;
    //getInputStream() 返回InputStream读取文件的内容
    InputStream getInputStream() throws IOException;

    default Resource getResource() {
        return new MultipartFileResource(this);
    }
    //transferTo(File dest) 用来把 MultipartFile 转换换成 File
    void transferTo(File var1) throws IOException, IllegalStateException;

    default void transferTo(Path dest) throws IOException, IllegalStateException {
        FileCopyUtils.copy(this.getInputStream(), Files.newOutputStream(dest));
    }
}

本文作者:西宫结弦

本文链接:https://www.cnblogs.com/NishimiyaShouko/p/15776025.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   西宫结弦  阅读(226)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起