A small input chain between FileInputStream and DataInputStream : Stream « File « SCJP






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

public class MainClass {
  public static void main(String[] argv) {
    try {
      // Construct the chain
      FileInputStream fis = new FileInputStream("fname");
      DataInputStream dis = new DataInputStream(fis);

      // Read
      double d = dis.readDouble();
      int i = dis.readInt();
      String s = dis.readUTF();

      // Close the chain
      dis.close(); // Close dis first, because it
      fis.close(); // was created last
    } catch (IOException e) {
    }

  }
}








9.3.Stream
9.3.1.InputStream and OutputStream
9.3.2.Low-Level Streams: FileInputStream
9.3.3.A filter connects to an InputStream or OutputStream and performs some transformation on the data
9.3.4.Construct a chain of DataOutputStream, BufferedOutputStream and FileOutputStream
9.3.5.Classes derived from Reader and Writer take locale information when converting between Unicode and other character systems.
9.3.6.A small input chain between FileInputStream and DataInputStream
9.3.7.Input chain between FileOutputStream and DataOutputStream
9.3.8.Using FileInputStream, FileOutputStream, and File classes.