读取数据流保存到指定的路径下
作者:互联网
/**
* 读取数据流保存到指定的路径下
* @param inputStream 输入流
* @param path 路径
* @param fileName 文件名称
*/
public static void saveFile(InputStream inputStream,String path,String fileName) throws IOException {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(inputStream);
bos = new BufferedOutputStream(new FileOutputStream(new File(path)));
int len = -1;
while((len = bis.read()) != -1){
bos.write(len);
}
bos.flush(); //刷新
} catch (FileNotFoundException e) {
log.error("文件读取异常!,原因:"+ e);
} catch (IOException e) {
log.error("文件读取异常!,原因:"+ e);
}finally{
if(bis!=null)
bis.close();
if(bos!=null)
bos.close();
}
}
标签:bos,读取数据,路径,指定,param,len,new,null,bis 来源: https://blog.csdn.net/weixin_43498023/article/details/121192486