DataOutputStream write(int) in Java

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

Syntax:

void java.io.DataOutputStream.write(int b) throws IOException

This method takes one argument. This method writes the specified byte to the underlying output stream.

Note: If no exception is thrown, the counter written is incremented by 1.

Parameters: One parameter is required for this method.

b: the byte 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 DataOutputStreamwrite2 {
    public static void main(String[] args) throws IOException {

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

        byte b = 'A';
        data.write(b);
        System.out.println("Successfully writes");
        data.close();

    }
}

Output:

Successfully writes


hello.txt

A

No comments:

Post a Comment