java.io.ByteArrayOutputStream Example in Java
September 28, 2013
java.io.ByteArrayOutputStream writes data in byte array inside it. java.io.ByteArrayOutputStream. ByteArrayOutputStream returns the same byte array by calling the method toByteArray. And then that byte array can be used to fulfill the requirements.
ByteArrayOutputStreamTest.java
package com.concretepage.io; import java.io.ByteArrayOutputStream; import java.io.IOException; public class ByteArrayOutputStreamTest { public static void main(String[] args) throws IOException { ByteArrayOutputStream baos = null; baos = new ByteArrayOutputStream(); String s = "Hello World!"; baos.write(s.getBytes()); byte[] b = baos.toByteArray(); for(int i=0; i<b.length; i++){ System.out.print(new Character((char)b[i])); } } }
Hello World!