TechieDrill Your World Of Technical Tutorials

ByteArrayInputStream

11.22.2009 · Posted in Java
import java.io.*;
class ByteArrayInputStreamDemo
{
public static void main(String [] args) throws IOException
{
byte data[]=”Here is a String”.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(data);
int ch;
while((ch = in.read()) !=-1)
{
System.out.println(ch+ ” “);
System.out.println((char)ch+” “);
}
}
}import java.io.*;
class ByteArrayInputStreamDemo
{
public static void main(String [] args) throws IOException
{
byte data[]=”Here is a String”.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(data);
int ch;
while((ch = in.read()) !=-1)
{
System.out.println(ch+ ” “);
System.out.println((char)ch+” “);
}
}
}

ByteArrayInputStream internally contains a buffer holding bytes which can be read by a stream. ByteArrayInputStream was established since JDK1.0. It is from InputStream hierarchy.

Sample code is placed below to understand ByteInputStream

import java.io.*;

class ByteArrayInputStreamDemo

{

public static void main(String [] args) throws IOException

{

byte data[]=”Here is a String”.getBytes();

ByteArrayInputStream in = new ByteArrayInputStream(data);


int ch;

while((ch = in.read()) !=-1)

{

System.out.println(ch+ ” “);

System.out.println((char)ch+” “);

}

}

}

Leave a Reply

You must be logged in to post a comment.