transferTo(OutputStream): This method is available in the java.io.ByteArrayInputStream class of Java.
Syntax:
long java.io.ByteArrayInputStream.transferTo(OutputStream out) throws IOException
This method takes one argument. This method reads all bytes from this input stream and writes the bytes to the given output stream in the order that they are read. In return, this input stream will be at end of the stream.
Parameters: One parameter is required for this method.
out: the output stream, non-null.
Returns: the number of bytes transferred.
Throws:
IOException - if an I/O error occurs when reading or writing
Approach
Java
import java.io.ByteArrayInputStream;import java.io.IOException;public class ByteArrayInputStreamtransferTo {public static void main(String[] args) throws IOException {byte buf[] = { 1, 2, 3, 4 };ByteArrayInputStream byteArrayInputStream =new ByteArrayInputStream(buf);System.out.println(byteArrayInputStream.transferTo(System.out));byteArrayInputStream.close();}}
Output:
4
No comments:
Post a Comment