The java.io.DataOutputStream.flush() method flushes the buffered output stream. It forces any buffered output bytes to be written out to the underlying output stream.
Code Examples:
1. This example uses a DataOutputStream to write an integer to a file and then flushes the stream to ensure the data is written:
import java.io.*;
public class Example { public static void main(String[] args) throws IOException { DataOutputStream dos = new DataOutputStream(new FileOutputStream("output.txt")); int num = 100; dos.writeInt(num); dos.flush(); } }
2. This example uses a DataOutputStream to write a string to a file and then flushes the stream to ensure the data is written:
import java.io.*;
public class Example { public static void main(String[] args) throws IOException { DataOutputStream dos = new DataOutputStream(new FileOutputStream("output.txt")); String message = "Hello, World!"; dos.writeUTF(message); dos.flush(); } }
Package Library:
The java.io.DataOutputStream class is part of the Java I/O API, which is in the java.io package.
Java DataOutputStream.flush - 30 examples found. These are the top rated real world Java examples of java.io.DataOutputStream.flush extracted from open source projects. You can rate examples to help us improve the quality of examples.