Share on Google+Share on Google+

Java Write To File Double

In this tutorial you will learn how to write to file primitive type double.

Java Write To File Double

In this tutorial you will learn how to write to file primitive type double.

Write to file primitive data type double there is a class DataOutputStream that provides a writeDouble() method to write a double value in binary files. writeDouble() method first converts the argument to a long and then writes the converted value in the output stream as a 8 byte quantity.

In the example given below I have created a method named writeToFileDouble() into which created an object of FileOutputStream and passes the file name to its instance to write the character-stream further passed this object to the BufferedOutputStream instance to write the characters efficiently.

Example :


class WriteToFileDouble
public static void main(String args[])
WriteToFileDouble wtfd = new WriteToFileDouble();
public void writeToFileDouble()
double[] dob = { 3.99, 124.30, 30.124};
FileOutputStream fos = null;
BufferedOutputStream bos = null;
DataOutputStream dos = null;
fos = new FileOutputStream("writeToFileDouble.txt");
bos = new BufferedOutputStream(fos);
dos = new DataOutputStream(bos);
for(int i=0; i<dob.length; i++)
catch(Exception e)

How to Execute this example :

After doing the basic process to execute a java program write simply on command prompt as :

javac to compile the program

And after successfully compilation to run simply type as :

java WriteToFileDouble

When you will execute this example a new file will be created at the specified place given by you with containing the text that you are trying to write into the file by java program.

Download Source Code


Posted on: January 19, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Java Write To File Double  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image