How to create ByteArrayInputStream() from partial array of bytes in Java

1 Answer

0 votes
package javaapplication1;

import java.io.ByteArrayInputStream;

public class JavaApplication1 {
 
    public static void main(String[] args) {
 
        String s = "java c# c c++";
                 
        try
        {
            byte[] byteArr = s.getBytes();
               
            ByteArrayInputStream bis = new ByteArrayInputStream(byteArr, 5, 2);
            
            int ch;
                 
            while ((ch = bis.read()) != -1)
                    System.out.print((char)ch);
                                               
        }
        catch(Exception e)
        {
              System.out.println(e.getMessage());
        }
     }
}
 
 
/*
 
run:
                    
c#
  
*/

 



answered Mar 17, 2017 by avibootz

Related questions

1 answer 226 views
1 answer 200 views
1 answer 179 views
1 answer 175 views
1 answer 179 views
...