zoukankan      html  css  js  c++  java
  • java 将文件流和文件名称转换为文件

    private class MultipartFileResource extends InputStreamResource {

    private String fileName;

    private InputStream inputStream;

    public MultipartFileResource(InputStream inputStream, String fileName) {
    super(inputStream);
    this.inputStream = inputStream;
    this.fileName = fileName;
    }

    @Override
    public String getFilename() {
    return this.fileName;
    }

    @Override
    public long contentLength() throws IOException {
    return inputStream.available();
    }

    @Override
    public boolean equals(Object obj) {
    return (obj == this || (obj instanceof MultipartFileResource && ((MultipartFileResource) obj).inputStream.equals(this.inputStream)));
    }
    }

    调用方法:

    List<MultipartFile> files

    for (MultipartFile file : files) {
    map.add("file", new MultipartFileResource(file.getInputStream(), file.getOriginalFilename()));
    }

  • 相关阅读:
    *Path Sum II
    *Path Sum
    Same Tree
    Symmetric Tree
    hprof网络连接
    gc
    java thread park
    sudo !!
    ecb gud
    jpda
  • 原文地址:https://www.cnblogs.com/jiehanshi/p/11269889.html
Copyright © 2011-2022 走看看