The use of DataOutputStream and DataInputStream: : Data Input Output « File Input Output « Java






The use of DataOutputStream and DataInputStream:

  

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

class DataIODemo {
  public static void main(String args[]) throws IOException {

    FileOutputStream fout = new FileOutputStream("Test.dat");
    DataOutputStream out = new DataOutputStream(fout);

    out.writeDouble(98.6);
    out.writeInt(1000);
    out.writeBoolean(true);

    out.close();

    FileInputStream fin = new FileInputStream("Test.dat");
    DataInputStream in = new DataInputStream(fin);

    double d = in.readDouble();
    int i = in.readInt();
    boolean b = in.readBoolean();

    System.out.println("Here are the values:  " + d + " " + i + " " + b);

    in.close();
  }
}

   
  








Related examples in the same category

1.Data IO Test 2Data IO Test 2
2.Data IO DemoData IO Demo
3.Data IO Test Data IO Test
4.Typical I/O stream configurations
5.ProgressMonitorInputStream Demo
6.IO demo: DataOutputStream and DataInputStream
7.Some simple file I-O primitives reimplemented in Java
8.ScanStreamTok - show scanning a file with StringTokenizer
9.Write some data in binary
10.Using transferTo() between channels
11.Controlling serialization by adding your own writeObject() and readObject() methodsControlling serialization by adding your own writeObject() and readObject() methods
12.Read Write Lock TestRead Write Lock Test
13.Bit InputStream