Wednesday, 31 August 2016

Java Tutorial : Java IO (ByteArrayOutputStream)

Click here to watch in Youtube :

Click the below Image to Enlarge
Java Tutorial : Java IO (ByteArrayOutputStream)
Java Tutorial : Java IO (ByteArrayOutputStream)
Java Tutorial : Java IO (ByteArrayOutputStream)

public class ByteArrayOutputStreamDemo

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

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

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

        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]);

Buffer as a string
Welcome to India.
Into array
Welcome to India.

Click the below link to download the code:

Github Link:

Bitbucket Link:

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