zoukankan      html  css  js  c++  java
  • java基础知识回顾之javaIO类--内存操作流ByteArrayInputStream和ByteArrayOutputSteam(操作字节数组)

    直接看代码:

    package cn.itcast.io.p6.bytestream;
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    
    public class ByteArrayStreamDemo {
    
        /**
         * @param args
         * @throws IOException 
         * 特点
         * 1.内存操作流
         * 2.不操作底层资源,不调用操作系统的底层资源,操作内存中的数据,内存流不需要关闭
         * 3.关闭流后还可以使用
         * 本例:内存操作流完成的一个大小写字母转换的程序:
         */
        public static void main(String[] args) {
            String str = "HELLO WORLD!";
            ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes());//将内容输入到内存中
            ByteArrayOutputStream bos = new ByteArrayOutputStream();//将内存中的数据输出
            int ch = 0;
            bis.skip(2);//跳过两个字节
            System.out.println(bis.available());//返回此输入流读取的(或跳过)剩余的字节数
            while((ch=bis.read())!=-1){
                bos.write(Character.toLowerCase(ch));//将大小字符转化成小写
            }
            System.out.println(bos.toString());
        }
    
    }

    输出:由于跳过两个字节,HELLO WORLD!总共12个字节,则剩余10个字节。

    10
    llo world!

     
  • 相关阅读:
    python3 网络编程
    python3 字典及其方法
    洛谷P2239 螺旋矩阵
    洛谷P4281 紧急会议
    洛谷 P4427 求和
    树的直径
    洛谷P3398 仓鼠找suger
    洛谷P3865 ST表
    洛谷P1638逛画展
    洛谷P1886 滑动窗口
  • 原文地址:https://www.cnblogs.com/200911/p/3909203.html
Copyright © 2011-2022 走看看