Friday 26 August 2016

Java Tutorial : Java IO (ByteArrayInputStream)


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

Click the below Image to Enlarge
Java Tutorial : Java IO (ByteArrayInputStream) 
Java Tutorial : Java IO (ByteArrayInputStream) 
Java Tutorial : Java IO (ByteArrayInputStream) 
ByteArrayInputStreamDemo.java
import java.io.ByteArrayInputStream;
import java.io.IOException;

public class ByteArrayInputStreamDemo
{

    public static void main(String[] args) throws IOException
    {
        ByteArrayInputStream byteArrayInputStream = null;

        try
        {
            String str = "Peter is going to India.";
            byte[] byteArray = str.getBytes();
            
            byteArrayInputStream = new ByteArrayInputStream(byteArray);
            int ch;
            while ((ch = byteArrayInputStream.read()) != -1)
            {
                System.out.print((char) ch);
            }
        }
        finally
        {
            if (byteArrayInputStream != null)
            {
                /*
                 * Closing a ByteArrayInputStream has no
                 * effect. The methods in this class can be
                 * called after the stream has been closed
                 * without generating an IOException.
                 */
                byteArrayInputStream.close();
            }
        }

    }
}
Output
Peter is going to India.
Refer:
Click the below link to download the code:
https://sites.google.com/site/ramj2eev1/home/javabasics/JavaIODemo_ByteArrayInputStream_Intro_App.zip?attredirects=0&d=1

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

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/94d38fdd49b2d33c14c088526d40f902c21a1e0d/BasicJava/JavaIODemo_ByteArrayInputStream_Intro_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