Wednesday 31 August 2016

Java Tutorial : Java IO (ByteArrayOutputStream)


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

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

public class ByteArrayOutputStreamDemo
{

    public static void main(String[] args) throws IOException
    {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

        String str = "Welcome to India.";
        byte[] byteArray = str.getBytes();
        byteArrayOutputStream.write(byteArray);

        System.out.println("Buffer as a string");
        /*
         * Returns String decoded from the buffer's
         * contents.
         */
        String content = byteArrayOutputStream.toString();
        System.out.println(content);

        System.out.println("----------------------------------");
        System.out.println("Into array");

        /*
         * Returns the current contents of this output
         * stream, as a byte array
         */
        byte b[] = byteArrayOutputStream.toByteArray();

        for (int i = 0; i < b.length; i++)
        {
            System.out.print((char) b[i]);
        }
    }

}
Output
Buffer as a string
Welcome to India.
----------------------------------
Into array
Welcome to India.

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

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

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