DataOutputStream writeLong(long) in Java

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

Syntax:

void java.io.DataOutputStream.writeLong(long v) throws IOException

This method takes one argument. This method writes a long to the underlying output stream as eight bytes, high byte first.

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

Parameters: One parameter is required for this method.

v: a long to be written.

Returns: NA

Throws:

IOException - if an I/O error occurs.

Approach

Java

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

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

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

        long v = 10001001L;
        data.writeLong(v);
        System.out.println("Successfully writes");
        data.close();

    }
}

Output:

Successfully writes


No comments:

Post a Comment