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(); } }
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.
+ 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);
}
}
}