Java.io.SequenceInputStream.read len() 方法


Java.io.SequenceInputStream.read len() 方法

package com.codingdict;



import java.io.*;



public class SequenceInputStreamDemo {



   public static void main(String[] args) {



      // create two  new strings with 5 characters each

      String s1 = "Hello";

      String s2 = "World";



      // create 2 input streams

      byte[] b1 = s1.getBytes();

      byte[] b2 = s2.getBytes();

      ByteArrayInputStream is1 = new ByteArrayInputStream(b1);

      ByteArrayInputStream is2 = new ByteArrayInputStream(b2);



      // create a new Sequence Input Stream

      SequenceInputStream sis = new SequenceInputStream(is1, is2);



      // create a new byte array

      byte arr[] = {'1', '2', '3', '4'};



      try {



         // read 3 chars and print the number of chars read

         System.out.print("" + sis.read(arr, 0, 3));



         // change line

         System.out.println();



         // close the streams

         sis.close();



      } catch (IOException ex) {

         ex.printStackTrace();

      }

   }

}