ByteArrayInputStream | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

ByteArrayInputStream

Why there is error giving in this code at this point 1)at new ByteArrayInputStream(b); 2) when I am using bis.read() method #code is this ....please check. package bytearray; import java.io.*; public class ByteArrayInputStream { public static void main(String[] args) throws Exception{ byte b[]= {'a','b','c','d','e','f','g','h'}; ByteArrayInputStream bis=new ByteArrayInputStream(b); int x; while((x=bis.read())!=-1) { System.out.print((char)x); } bis.close(); } }

27th Oct 2022, 4:57 PM
Minhaj Haider
Minhaj Haider - avatar
2 Answers
+ 4
So in your program you are importing java.io but then you declare a class with the same name ByteArrayInputStream that was already there in the standard library. So you effectively overwrite the content of standard JDK :) What is the solution? Change the name of your class and it will work fine.
27th Oct 2022, 5:22 PM
Tibor Santa
Tibor Santa - avatar
+ 1
import java.io.*; public class Program { //debug public static void main(String[] args) throws Exception{ byte b[]= {'a','b','c','d','e','f','g','h'}; ByteArrayInputStream bis=new ByteArrayInputStream(b); int x; while((x=bis.read())!=-1) { System.out.print((char)x); } } }
27th Oct 2022, 7:54 PM
Solo
Solo - avatar