How to create ByteArrayInputStream from partial array of bytes - Java File Path IO

Java examples for File Path IO:ByteArrayInputStream

Description

How to create ByteArrayInputStream from partial array of bytes

Demo Code

 
import java.io.ByteArrayInputStream;
 
public class Main {
 
        public static void main(String[] args) {
                String str = "Byte Array InputStream test";
                byte[] bytes = str.getBytes();
               //from   ww  w.  jav  a 2s  .c o m
                 ByteArrayInputStream bis = new ByteArrayInputStream(bytes, 5, 5);
                 int ch;
                 
                 while ((ch = bis.read()) != -1)
                 {
                        System.out.print((char)ch);
                 }
               
        }
}

Result


Related Tutorials