zoukankan      html  css  js  c++  java
  • 20180805-Java ByteArrayInputStream类

    ByteArrayInputStream bArray = new ByteArrayInputStream(byte [] a);

    ByteArrayInputStream bArray = new ByteArrayInputStream(
    byte []a,int off,int len
    );

    下面的例子演示了ByteArrayInputStream 和 ByteArrayOutputStream的使用:

    package study0805;

    import java.io.*;
    public class ByteStreamTest {
    public static void main(String[] args) throws IOException {
    ByteArrayOutputStream bOutput = new ByteArrayOutputStream(12);
    while (bOutput.size() != 10) {
    // 获取用户输入值
    bOutput.write(System.in.read());
    }

    byte b[] = bOutput.toByteArray();
    System.out.println("Print the content");

    for (int x = 0; x < b.length; x++) {
    // 打印字符
    System.out.println((char) b[x] + " ");
    }
    System.out.println("aaaaaaaaaaaa");

    int c;
    ByteArrayInputStream bInput = new ByteArrayInputStream(b);

    System.out.println("Converting characters to Upper case");
    for(int y=0;y<1;y++){
    while((c = bInput.read())!=-1){
    System.out.println(Character.toUpperCase((char)c));
    }
    bInput.reset();
    }
    }
    }




    Java ByteArrayInputStream类

    字节数组输入流在内存中创建一个字节数组缓冲区,从输入流读取的数据保存在该字节数组缓冲区中。创建字节数组输入流对象有以下几种方式。

    接收字节数组作为参数创建:

    另一种创建方式是接收一个字节数组,和两个整形变量 off、len,off表示第一个读取的字节,len表示读取字节的长度。

    成功创建字节数组输入流对象后,可以参见以下列表中的方法,对流进行读操作或其他操作。

    方法 描述
    public int read() 从此输入流中读取下一个数据字节。

    public int read(byte[] r, int off, int len) 将最多 len 个数据字节从此输入流读入字节数组。

    public int available() 返回可不发生阻塞地从此输入流读取的字节数。

    public void mark(int read) 设置流中的当前标记位置。

    public long skip(long n) 从此输入流中跳过 n 个输入字节。

    备注:随笔中内容来源于网上资料整理,仅供参考。

  • 相关阅读:
    Spark中文指南(入门篇)-Spark编程模型(一)
    Scala入门学习笔记三--数组使用
    沃老师学生的成绩
    Codeforces Round #461 (Div. 2) DRobot Vacuum Cleaner
    Codeforces Round #461 (Div. 2) ABC
    Educational Codeforces Round 37 (Rated for Div. 2) ABC
    Codeforces Round #460 (Div. 2) D Substring
    Codeforces Round #460 (Div. 2) ABC
    中缀式转后缀式求表达式结果
    计算器——python正则表达式
  • 原文地址:https://www.cnblogs.com/Alanf/p/9425511.html
Copyright © 2011-2022 走看看