DataInputStream ReadFloat() Example
returns the next four bytes of this input stream, interpreted as a float.
DataInputStreamclass ReadFloat() method example. This example shows you how to use ReadFloat() method.This method returns the next four bytes of this input stream, interpreted as a float.
Here is the code:-
/**
* @Program that returns the next four bytes of this input stream, interpreted
as a float.
* ReadFloat.java
* Author:-RoseIndia Team
* Date:-07-jun-2008
*/
import java.io.*;
public class ReadFloat {
public static void main(String[] args)throws IOException {
float fF = 245;
FileOutputStream fos = new FileOutputStream("Linux.txt");
DataOutputStream dos = new DataOutputStream(fos);
dos.writeFloat(fF);
dos.flush();
dos.close();
FileInputStream fis = new FileInputStream("Linux.txt");
DataInputStream dis = new DataInputStream(fis);
//returns the next two bytes of this input stream, interpreted
//as a float.
double d = dis.readFloat();
System.out.println("The next eight bytes of this input stream is :" + d);
}
} |
Output of the Program
| The next eight bytes of this input stream is :245.0 |
|