import java.io.*;


public class IOtest{

  final int MAX=1000000;

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


  public  void test1() {
     long t1,t2;
     int i;
	t1 =  System.currentTimeMillis();
    try {
      FileOutputStream Fout = new FileOutputStream( "test.bin" );
      //BufferedOutputStream Bkan=new BufferedOutputStream(Fout);
      DataOutputStream Dout = new DataOutputStream(Fout);
      for (i=0; i<MAX; i++) {
        Dout.writeInt(10000000+i);
      }

      Fout.close(); 
 	 t2 =  System.currentTimeMillis();
      System.out.println("Write Zeit binaer: "+(t2-t1) );
    }
    catch (IOException ee) {
           System.err.println("IOException: " + ee);
       }  
   } // test1

  public  void test2() {
     long t1,t2;
     int i;
	t1 =  System.currentTimeMillis();
    try {
      FileOutputStream Fout = new FileOutputStream( "test.txt" );
      // BufferedOutputStream Bkan=new BufferedOutputStream(Fout);
      PrintStream p = new PrintStream(Fout);
      for (i=0; i<MAX; i++) {
        p.println(10000000+i);
      }
      Fout.close(); 
      p.close();

 	 t2 =  System.currentTimeMillis();
      System.out.println("Write Zeit ASCII: "+(t2-t1) );
    }
    catch (IOException ee) {
           System.err.println("IOException: " + ee);
       }  
    } // test2


  public  void test3() {
     long t1,t2;
     int i;
     int j;
	t1 =  System.currentTimeMillis();
    try {
      FileInputStream Fin = new FileInputStream( "test.bin" );
      //BufferedOutputStream Bkan=new BufferedOutputStream(Fout);
      DataInputStream Din = new DataInputStream(Fin);
      for (i=0; i<MAX; i++) {
        j = Din.readInt();
      }

      Fin.close(); 
 	 t2 =  System.currentTimeMillis();
      System.out.println("Read Zeit binaer: "+(t2-t1) );
    }
    catch (IOException ee) {
           System.err.println("IOException: " + ee);
       }  
   } // test3

  public  void test4() {
     long t1,t2;
     int i;
     String sLine;
      int iValue;
    FileInputStream Fin;
    InputStreamReader Iin;
    LineNumberReader Din;
	t1 =  System.currentTimeMillis();

    try {
      Fin = new FileInputStream("test.txt");
      Iin = new InputStreamReader(Fin);
      Din = new LineNumberReader(Iin);
      for (i=0; i<MAX; i++) {
        sLine = Din.readLine();
        // daten.setZahlen(Integer.parseInt(TInteger.getText()));
        iValue = Integer.parseInt(sLine);
         // System.out.println(iValue);
      }
      Fin.close(); 
 	 t2 =  System.currentTimeMillis();
      System.out.println("Read Zeit ASCII: "+(t2-t1) );
    pause();
    }
    catch (IOException ee) {
           System.err.println("IOException: " + ee);
       }  
    } // test4

  public static void main(String[] args) {
    IOtest prog = new IOtest();
    prog.test1();
    prog.test2();
    prog.test3();
    prog.test4();
    pause();
  }
}
