Java ByteArrayOutputStream .writeTo (OutputStream out)
Syntax
ByteArrayOutputStream.writeTo(OutputStream out) has the following syntax.
public void writeTo(OutputStream out) throws IOException
Example
In the following code shows how to use ByteArrayOutputStream.writeTo(OutputStream out) method.
//ww w .j a v a 2s . c om
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class Main {
public static void main(String[] args) throws IOException {
byte[] bs = { 65, 66, 67, 68, 69, 70, 71, 72 };
OutputStream os = new ByteArrayOutputStream();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
baos.write(bs);
baos.writeTo(os);
System.out.println(os.toString());
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »