将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();

    }
}

猜你喜欢

转载自www.cnblogs.com/chong-zuo3322/p/13184812.html