DataOutputStream Flush() Example

Flushes the data output stream.


DataOutputStreamclass Flush() method example. This example shows you how to use Flush() method.This method Flushes the data output stream.

Here is the code:-
/**
 * @Program that Flushes this data output stream.
 * Flush.java 
 * Author:-RoseIndia Team
 * Date:-09-jun-2008
 */
import java.io.*;
public class Flush {
public static void main(String[] args)throws IOException {
byte[]b={1,2,3,4,5};
FileOutputStream fos=new FileOutputStream("g.txt");    
DataOutputStream dos=new DataOutputStream(fos);
//Writes len bytes from the specified byte array starting at offset
dos.write(b,2,b.length-2);
//Flushes this data output stream.
dos.flush();
//Closes this data output stream.
dos.close();
FileInputStream fis=new FileInputStream("g.txt");    
DataInputStream dis=new DataInputStream(fis);
System.out.println("Bytes to be written out to the stream: "+dis.read(b));    
    }
}

Output of the Program
 Bytes to be written out to the stream: 3

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US