The writeTo() method of ByteArrayOutputStream class in Java is used to write the contents of this ByteArrayOutputStream to the specified OutputStream that is passed as the argument. In this method OutputStream is passed as a parameter and the ByteArrayOutputStream is copied to this OutputStream.
public void writeTo(OutputStream outputStr) throws IOException
Parameters: This method accepts one parameter outputStr which represents the OutputStream to which the content of ByteArrayOutputStream is to be copied.
Return value: The method does not return any value.
Exceptions: This method throws IOException if an I/O error occurs.
Below programs illustrate writeTo() method in ByteArrayOutputStream class in IO package:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.