Online Java Compiler By
JavaTpoint.com
import java.io.ByteArrayInputStream; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; public class ObjectInputStreamreadByteExample2 { public static void main(String[] args) throws IOException { InputStream instream = null; DataInputStream datainsstream = null; byte[] barray = {'j', 'a', 'v', 'a', 'T', 'p', 'o', 'i', 'n', 't'}; try { // create new byte array input stream instream = new ByteArrayInputStream(barray); // create data input stream datainsstream = new DataInputStream(instream); // readBoolean till the data available to read for(int i=0;i<=barray.length;i++){ // while( datainsstream.available() >0) { // read one single byte byte bt = datainsstream.readByte(); // print the byte System.out.print(bt+" "); } } catch(Exception e) { // if any I/O error occurs } } }
Output