当前位置: 首页 > news >正文

(五)IO流之ByteArrayInput/OutputStream

ByteArrayInputStream:是把字节数组当成源的输入流

    String string="hello shanghai";
    ByteArrayInputStream bis=new ByteArrayInputStream(string.getBytes());
    int data=-1;
    while ((data=bis.read())!=-1) {
        System.out.print((char)data);
        
    }
    //bis.close();无效

 

ByteArrayOutputStream:是把字节数组当做目标的输出流

ByteArrayOutputStream bos=new ByteArrayOutputStream();
     bos.write(97);
     bos.write("hello world".getBytes());
     byte[] buff=bos.toByteArray();
     for(byte data:buff) {
         System.out.println((char)data);
     }
     
     FileOutputStream fos=new FileOutputStream("D:\\aa.txt",true);
     bos.writeTo(fos);//把 ByteArrayOutputStream内部缓冲区的数据写到对应的文件输出流中
     fos.close();

 

转载于:https://www.cnblogs.com/tanlei-sxs/p/9665425.html

相关文章:

  • Java 之 Map 的键,值多重排序问题解决方案
  • 西安高校加紧人工智能学科布局
  • CentOS搭建samba文件共享传输服务
  • 容器服务kubernetes弹性伸缩高级用法
  • TERMIOS详解【转】
  • 求连续数字的和------------------------------用while的算法思想
  • Zabbix3.0基础教程之二:item、trigger、action、graph配置
  • BZOJ2216: [Poi2011]Lightning Conductor(DP 决策单调性)
  • 递增链表的插入
  • (转) SpringBoot:使用spring-boot-devtools进行热部署以及不生效的问题解决
  • Linux 环境变量的配置解决(-bash: jps: command not found)问题
  • Tomcat学习—Tomcat的简介和目录以及配置文件介绍(Windows环境)
  • Kafka简介
  • Jvm(49),指令集----异常处理指令
  • centos7设置开机启动
  • 2018一半小结一波
  • canvas实际项目操作,包含:线条,圆形,扇形,图片绘制,图片圆角遮罩,矩形,弧形文字...
  • CentOS 7 防火墙操作
  • DataBase in Android
  • Electron入门介绍
  • ESLint简单操作
  • Intervention/image 图片处理扩展包的安装和使用
  • JavaScript 无符号位移运算符 三个大于号 的使用方法
  • MySQL数据库运维之数据恢复
  • Spring Cloud(3) - 服务治理: Spring Cloud Eureka
  • vagrant 添加本地 box 安装 laravel homestead
  • 从setTimeout-setInterval看JS线程
  • 从零搭建Koa2 Server
  • 互联网大裁员:Java程序员失工作,焉知不能进ali?
  • 聊聊spring cloud的LoadBalancerAutoConfiguration
  • 深入浏览器事件循环的本质
  • 数组的操作
  • 【运维趟坑回忆录】vpc迁移 - 吃螃蟹之路
  • #1015 : KMP算法
  • (1)(1.9) MSP (version 4.2)
  • (6)STL算法之转换
  • (PWM呼吸灯)合泰开发板HT66F2390-----点灯大师
  • (zt)基于Facebook和Flash平台的应用架构解析
  • (附源码)springboot建达集团公司平台 毕业设计 141538
  • (附源码)springboot学生选课系统 毕业设计 612555
  • (附源码)ssm基于微信小程序的疫苗管理系统 毕业设计 092354
  • (论文阅读22/100)Learning a Deep Compact Image Representation for Visual Tracking
  • (四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB
  • (一)eclipse Dynamic web project 工程目录以及文件路径问题
  • (原創) 如何使用ISO C++讀寫BMP圖檔? (C/C++) (Image Processing)
  • (转)iOS字体
  • (转)总结使用Unity 3D优化游戏运行性能的经验
  • ./configure,make,make install的作用
  • .describe() python_Python-Win32com-Excel
  • .NET Framework杂记
  • .NET MVC之AOP
  • .Net 垃圾回收机制原理(二)
  • .NET中的Exception处理(C#)
  • @EnableWebMvc介绍和使用详细demo
  • [ 网络基础篇 ] MAP 迈普交换机常用命令详解