john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

file scan measure method execution time

// also consider  System.nanoTime() and readline() with strtok()
import java.io.*;
import java.util.*;

public class FileScan
{
  public static void main( String[] args ) throws IOException
  {
    long start = System.currentTimeMillis();
    commandLineParameterCheck( args );
        Scanner s = null;
      try {
        s = new Scanner( new BufferedReader( new FileReader( args[0] ) ));

        while( s.hasNext() )
        {
            System.out.println( s.next() );
        }
        }finally {
        if (s != null) {    s.close();  }
      }
      long end = System.currentTimeMillis();
      long duration = end - start;
      System.out.println( duration + " ms" );
  }

  private static void commandLineParameterCheck( String[] args )
  {
      if( args.length != 1 || args[0].isEmpty() )
        {
            System.out.println( args.length + " does not equal the 1 required arguments.");
            System.out.println( "version 0.1: java -jar filescan.jar filename" );
            System.exit( 1 );
        }
  }
} //end class

  • « Centos GLIBCXX 3.4.9 not found
  • file first line second line detection »

Published

Nov 30, 2011

Category

java

~88 words

Tags

  • execution 1
  • file 92
  • java 252
  • measure 1
  • method 3
  • scan 2
  • time 13