Wednesday, 31 August 2016

Java Tutorial : Java IO (ByteArrayInputStream Constructors)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=5Tq1G2K5xaM&list=UUhwKlOVR041tngjerWxVccw

ByteArrayInputStreamDemo.java
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class ByteArrayInputStreamDemo
{

    public static void main(String[] args) throws IOException
    {
        String str = "abcdefghijklmnopqrstuvwxyz";
        byte[] byteArray = str.getBytes();

        ByteArrayInputStream byteArrayInputStream1 = new ByteArrayInputStream(byteArray);

        /*
         * The byteArrayInputStream1 contains all letters.
         */
        displayContent(byteArrayInputStream1);

        ByteArrayInputStream byteArrayInputStream2 = new ByteArrayInputStream(byteArray, 0, 3);

        /*
         * The byteArrayInputStream2 contains only the first
         * three letters.
         */
        displayContent(byteArrayInputStream2);

    }

    private static void displayContent(ByteArrayInputStream byteArrayInputStream)
    {
        int ch;
        while ((ch = byteArrayInputStream.read()) != -1)
        {
            System.out.print((char) ch);
        }
        System.out.println();
    }
}
Output
abcdefghijklmnopqrstuvwxyz
abc

Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_ByteArrayIS_Cons_App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/JavaIODemo_ByteArrayIS_Cons_App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d261aab7f0b47dd247e532c02763fe1d7053f5d3/BasicJava/JavaIODemo_ByteArrayIS_Cons_App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • Kids Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge