DataOutputStream WriteFloat() Example

Converts the float argument to an int using the floatToIntBits method


DataOutputStreamclass WriteFloat() method example. This example shows you how to use WriteFloat() method.This method Converts the float argument to an int using the floatToIntBits method in class Float, and then writes that int value to the underlying output stream as a 4-byte quantity, high byte first.

Here is the code:-
/**
 * @Program that Converts the float argument to an int using the
    floatToIntBits method in class Float, and then writes that int value to the 
    underlying output stream
 * WriteFloat.java 
 * Author:-RoseIndia Team
 * Date:-09-jun-2008
 */
import java.io.*;
public class WriteFloat {
public static void main(String[] args)throws IOException {
float f=23.5f;
FileOutputStream fos=new FileOutputStream("g.txt");    
DataOutputStream dos=new DataOutputStream(fos);
//Converts the float argument to an int using the floatToIntBits.
dos.writeFloat(f);
FileInputStream fis=new FileInputStream("g.txt");    
DataInputStream dis=new DataInputStream(fis);
System.out.println("Float to the underlying output stream is : "+dis.readFloat());
     
    }
}

Output of the Program
 Float to the underlying output stream is : 23.5

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

HOME | COPYRIGHT | CONTACT US