1:byte[]转换为InputStream 
InputStream sbs = new ByteArrayInputStream(byte[] buf);

2:InputStream转换为InputStreambyte[] 
ByteArrayOutputStream swapStream = new ByteArrayOutputStream(); 
byte[] buff = new byte[100]; //buff用于存放循环读取的临时数据 
int rc = 0; 
while ((rc = inStream.read(buff, 0, 100)) > 0) { 
swapStream.write(buff, 0, rc); 

byte[] in_b = swapStream.toByteArray(); //in_b为转换之后的结果

    1. import java.io.ByteArrayInputStream;
    2. import java.io.ByteArrayOutputStream;
    3. import java.io.IOException;
    4. import java.io.InputStream;
    5. public class ByteToInputStream {
    6. public static final InputStream byte2Input(byte[] buf) {
    7. return new ByteArrayInputStream(buf);
    8. }
    9. public static final byte[] input2byte(InputStream inStream)
    10. throws IOException {
    11. ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
    12. byte[] buff = new byte[100];
    13. int rc = 0;
    14. while ((rc = inStream.read(buff, 0, 100)) > 0) {
    15. swapStream.write(buff, 0, rc);
    16. }
    17. byte[] in2b = swapStream.toByteArray();
    18. return in2b;
    19. }
    20. }

byte[]和InputStream的相互转换的更多相关文章

  1. byte[]和InputStream的相互转换[转载]

    1:byte[]转换为InputStream InputStream sbs = new ByteArrayInputStream(byte[] buf); 2:InputStream转换为Input ...

  2. byte[],File和InputStream的相互转换

    File.FileInputStream 转换为byte[] File file = new File("test.txt"); InputStream input = new F ...

  3. Android Bitmap与DrawAble与byte[]与InputStream之间的转换工具类【转】

    package com.soai.imdemo; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; ...

  4. java中outputStream与inputStream的相互转换

    package com.boco.test; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; im ...

  5. Java 中byte 与 char 的相互转换 Java基础 但是很重要

    char转化为byte: public static byte[] charToByte(char c) {        byte[] b = new byte[2];        b[0] = ...

  6. Java中字符串和byte数组之间的相互转换

    1.将字符转换成byte数组 String str = "罗长"; byte[] sb = str.getBytes(); 2.将byte数组转换成字符 byte[] b={(by ...

  7. inputStream、File、Byte、String等等之间的相互转换

    一:inputStream转换 1.inputStream转为byte //方法一 org.apache.commons.io.IOUtils包下的实现(建议) IOUtils.toByteArray ...

  8. byte数组和File,InputStream互转

    1.将File.FileInputStream 转换为byte数组: File file = new File("file.txt"); InputStream input = n ...

  9. java 中 byte[]、File、InputStream 互相转换

    1.将File.FileInputStream 转换为byte数组: File file = new File("test.txt"); InputStream input = n ...

随机推荐

  1. JQuery 多选按钮checkbox

    JQuery 多选按钮checkbox 在需要全选和选择部分的时候我们就需要多选在这里主要介绍了具体的实现 JQuery $(function () { //全选或全不选 $("#allbo ...

  2. 理解 bashrc 和 profile(转)

    转自:https://wido.me/sunteya/understand-bashrc-and-profile/ 在一般的 linux 或者 unix 系统中, 都可以通过编辑 bashrc 和 p ...

  3. vbs鼠标方法——模拟鼠标按键

    '*********************************************************************** ' 代码开始 '******************* ...

  4. nefu 179 珠子(最长递增子序列问题)

    Description 小林有一串珠子,是由很多个大小不同的珠子串联在一起组成的圆环型的,且其中每个珠子的大小可以用int型的整数来表示.小林有一个爱好就是数珠子,他想数那些位置相邻而且大小只相差1的 ...

  5. mysql 排序后获得某行的位置

    假设有test表,下图为表机构和数据,score表示积分.现在要查询积分排名为第几的id?? 查询语句 select id,score,(@rowno:=@rowno+1) as rowno from ...

  6. Thinkphp与Ucenter整合笔记

    ucenter手册:http://www.phpddt.com/manual/ucenter/html/index.htm 参考:http://www.thinkphp.cn/topic/1557.h ...

  7. 关于ckeditor过滤掉html样式标签之我见

    1.CKEDITOR编辑器属性可以通过修改/ckeditor/config.js文件来控制 //标签过滤默认是开启的,默认会过了<style>样式标签设置为true可关闭过滤config. ...

  8. 制作 macOS Sierra 正式版U盘USB启动安装盘方法教程 (全新安装 Mac 系统)

    使用命令行创建制作 macOS Sierra 正式版 USB 安装盘 1.准备一个 8GB 或更大容量的 U盘,并备份好里面的所有资料. 2.下载好 macOS Sierra 正式版的安装程序(app ...

  9. ios中关于UIImagePickerController的一些知识总结

    记得添加MobileCoreServices.framework 及导入#import <MobileCoreServices/MobileCoreServices.h> @interfa ...

  10. linux跨主机复制文件或文件夹

    复制文件基本格式:(本地到远程) scp 文件名 用户名@ip:文件全目录 如果是文件夹加上参数 -r scp -r 基础目录 用户名@ip:目录 栗子: scp local_file remote_ ...