Java DataOutputStream Class
DataOutputStream allows you to write primitive data to the output stream. It implements the DataOutput interface. DataOutput interface defines a method to convert primitive values into a sequence of bytes.
Syntax:
public class DataOutputStream extends FilterOutputStream implements DataOutput
To create an OutputStream
DataOutputStream out = DataOutputStream(OutputStream out);
DataOutputStream Class Methods
| S.No | Method | Description |
|---|---|---|
| 1 | Public final int write(byte [] b) | It is used to writes the current number of bytes written to this data output stream. |
| 2 | void writeByte(int m) | It is used to write a byte to the output stream |
| 3 | public final void write(byte[] w, int off, int len) | It is used to write len bytes of data to the output stream. |
| 4 | public final void writeBoolean(boolean b) | It is used to write Boolean to the output stream as a 1-byte value. |
| 5 | Public final void writeBytes(String s) | It is used to write string to the output stream as a sequence of bytes. |
| 6 | Public void flush() | It is used to flushes the data output stream. |
Example:
import java.io.*;
public class DataOutputStreamDemo {
public static void main(String args[]) throws IOException{
FileOutputStream fout = new FileOutputStream("Out.txt");
DataOutputStream out = new DataOutputStream(fout);
out.writeInt(100);
out.flush();
out.close();
System.out.println("Success");
}
}
Output
Success
Out.txt
100
Quickly Find What You Are Looking For
OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.
point.com