zoukankan      html  css  js  c++  java
  • ByteArrayOutputStream 与InputStream 互相转换

    InputStream 转为 ByteArrayOutputStream

    public Reader(InputStream input) {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    byte[] buffer = new byte[1024];
    int len;
    try {
    while ((len = input.read(buffer)) > -1) {
    baos.write(buffer, 0, len);
    }
    baos.flush();
    } catch (IOException e) {
    throw new Exception("Illegal flow.");
    } finally {
    try {
    input.close();
    } catch (IOException e) {
    logger.error("file stream shutdown failed.");
    }
    }
    this.baos = baos;
    }
     
    ByteArrayOutputStream 转为 InputStream

    private InputStream streamTran(ByteArrayOutputStream in) {
    return new ByteArrayInputStream(in.toByteArray());
    }

    ————————————————
    版权声明:本文为CSDN博主「Mr-先森你好」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
    原文链接:https://blog.csdn.net/u011067966/article/details/97757260

  • 相关阅读:
    #考研碎碎念#
    #考研笔记#计算机之病毒
    #考研笔记#计算机之多媒体应用
    #考研笔记#计算机之PPT问题
    第六章深入理解类
    第五章方法
    类的基本教程
    类型存储变量
    C#和.net框架
    C#编程概述
  • 原文地址:https://www.cnblogs.com/javalinux/p/15693466.html
Copyright © 2011-2022 走看看