将InputStream文件流转换为File文件

package com.XXX.common.utils.image;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;


public class InputStreamToFile {
    /**
     * 将InputStream写入本地文件
     * @param destination 写入本地目录
     * @param input 输入流
     * @throws IOException IOException
     */
    public static void writeToLocal(String destination, InputStream input)
            throws IOException {
        int index;
        byte[] bytes = new byte[1024];
        FileOutputStream downloadFile = new FileOutputStream(destination);
        while ((index = input.read(bytes)) != -1) {
            downloadFile.write(bytes, 0, index);
            downloadFile.flush();
        }
        input.close();
        downloadFile.close();

    }
}

转载于:https://my.oschina.net/u/4131327/blog/3068592

你可能感兴趣的:(将InputStream文件流转换为File文件)