BufferedOutputStream write(byte[], int, int) in Java

write(byte[], int, int): This method is available in the java.io.BufferedOutputStream class of Java.

Syntax:

void java.io.BufferedOutputStream.write(byte[] b, int off, int len) throws IOException

This method takes three arguments. This method writes len bytes from the specified byte array starting at offset off to this buffered output stream.

Parameters: Three parameters are required for this method.

b: the data.

off: the start offset in the data.

len: the number of bytes to write.

Returns: NA

Throws:

IOException - if an I/O error occurs.

Approach

Java

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class BufferedOutputStreamwrite2 {
    public static void main(String[] args) throws IOException {

        FileOutputStream fileOutputStream =
new FileOutputStream("D:\\hello.txt");

        BufferedOutputStream bufferedOutputStream =
new BufferedOutputStream(fileOutputStream);

        byte b[] = { 1, 2, 3, 4 };
        int off = 0, len = 2;
        bufferedOutputStream.write(b, off, len);

        System.out.println("Write Success");

        bufferedOutputStream.close();
    }
}

Output:

Write Success


No comments:

Post a Comment