import java.io.*;

    // Schreiben und lesen von integer und double
    // Schreiben und lesen eines String

  public class Readwrite_int_double_1 {

  private static void pause() {
    try {
      System.in.read();
    }
    catch (IOException e) {
    }
  }  // pause


  private void write1() {
     try {
          System.out.println("write1");
          FileOutputStream fout = new FileOutputStream("readwrite1.bin");  // byteweise
           		// Umbau zur Ausgabe nun mittels primitiver Datentypen
          DataOutputStream dout = new DataOutputStream(fout);
          int i=1234;
          dout.writeInt(i);  // 4 Bytes
          float f = 123.4567f;
          dout.writeFloat(f); 
          double d = 123.4567;
          dout.writeDouble(d); 
          System.out.println("int i: "+i);
          System.out.println("float f: "+f);
          System.out.println("double d: "+d);
          dout.close();
      }
      catch (IOException e) {
           System.err.println("IOException: " + e);
      }
    }  // write1

  private void read1() {
     System.out.println("\n\nread1");
    try {
          FileInputStream fin = new FileInputStream("readwrite1.bin");  // byteweise
           		// Ausgabe nun mittels primitiver Datentypen
          DataInputStream din = new DataInputStream(fin);
          int i;
          i = din.readInt();  // 4 Bytes
          float f = (float)din.readFloat();
          double d = din.readDouble(); 
          System.out.println("int i: "+i);
          System.out.println("float f: "+f);
          System.out.println("double d: "+d);
          din.close();
        }
        catch (IOException e) {
            System.err.println("IOException: " + e);
        }
  }  // read1

  private int readByte(DataInputStream din) {
    int i1=0;
    try {
      i1 = (int) din.readByte();
      if (i1<0) i1+=256;
    }
    catch (IOException e) {
       System.err.println("IOException: " + e);
    }
    return i1;
  }

  private void read1a() {
     System.out.println("\n\nread1a");
    try {
          FileInputStream fin = new FileInputStream("readwrite1.bin");  // byteweise
           		// Ausgabe nun mittels primitiver Datentypen
          DataInputStream din = new DataInputStream(fin);
          int i;
          i = din.readInt();  // 4 Bytes
          int i1 = readByte(din);
          int i2 = readByte(din);
          int i3 = readByte(din);
          int i4 = readByte(din);
          // float f = din.readFloat();
          double d = din.readDouble(); 
          System.out.println("int i: "+i);
           // 42F6 E9D5
          System.out.println("float f: "+Integer.toHexString(i1)+"  "+Integer.toHexString(i2)
                   +"  "+Integer.toHexString(i3)+"  "+Integer.toHexString(i4) );
          System.out.println("double d: "+d);
          din.close();
        }
        catch (IOException e) {
            System.err.println("IOException: " + e);
        }
  }  // read1

 private void write2() {
     System.out.println("\n\nwrite2");
    try {
          FileOutputStream fout = new FileOutputStream("readwrite1.bin");  // byteweise
           		// Ausgabe nun mittels primitiver Datentypen
          DataOutputStream dout = new DataOutputStream(fout);
          String s = "abcdef";
          dout.writeUTF(s); 
          System.out.println("String s: "+s);
          dout.close();
     }
      catch (IOException e) {
          System.err.println("IOException: " + e);
      }
   }  // write2

  private void read2() {
     System.out.println("\n\nread2");
    try {
          FileInputStream fin = new FileInputStream("readwrite1.bin");  // byteweise
           		// Ausgabe nun mittels primitiver Datentypen
          DataInputStream din = new DataInputStream(fin);
          String s="";
          s = din.readUTF(); 
          System.out.println("String s: "+s);
          din.close();
        }
        catch (IOException e) {
            System.err.println("IOException: " + e);
        }
   }  // read2

  public static void main(String argv[]) {
      Readwrite_int_double_1  main = new Readwrite_int_double_1();
main.write2();
//      main.write1();
 //     main.read1();
/*
      
      main.read1a();

      main.write2();
      main.read2();
*/
      pause();
  }  // main

}



