DataOutputStream write(byte[]) in Java

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

Syntax:

void java.io.FilterOutputStream.write(byte[] b) throws IOException

This method writes b.length bytes to this output stream.

Parameters: One parameter is required for this method.

b: the data to be written.

Throws: IOException - if an I/O error occurs.

Approach

Java

import java.io.DataOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;

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

        FileOutputStream file =
new FileOutputStream("D:\\hello.txt");
        DataOutputStream data = new DataOutputStream(file);

        byte b[] = { 65, 66, 67 };
        data.write(b);
        System.out.println("Successfully writes");
        data.close();

    }
}

Output:

Successfully writes


hello.txt

ABC

No comments:

Post a Comment