All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.gitee.huanminabc.utils_common.file.WriteStreamToFileUtil Maven / Gradle / Ivy

There is a newer version: 1.0.5-RELEASE
Show newest version
package com.gitee.huanminabc.utils_common.file;

import com.gitee.huanminabc.utils_common.base.UniversalException;

import java.io.*;
import java.nio.file.Files;

public class WriteStreamToFileUtil {
    
    
    //将InputStream写入到文件中
    public static void writeInputStreamToFile(InputStream inputStream, File file) {
        try (BufferedInputStream bis = new BufferedInputStream(inputStream);
             BufferedOutputStream bos = new BufferedOutputStream(Files.newOutputStream(file.toPath()));) {
            byte[] data = new byte[4096];
            int len;
            while ((len = bis.read(data)) != -1) {
                bos.write(data, 0, len); // 写入数据
            }
        } catch (IOException e) {
             UniversalException.logError(e);
        }
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy