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) |
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:
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:
No comments:
Post a Comment