Thursday, October 30, 2014

Java Program to read integers from file with Scanner class


import java.util.Scanner;
import java.io.File;
import java.io.IOException;

public class ReadIntegers
{
    public static void main(String[] args)
    { try
{   Scanner s = new Scanner( new File("integers.dat") );
   while( s.hasNextInt() )
   { System.out.println( s.nextInt() );
   }
}
catch(IOException e)
{ System.out.println( e );
}
    }
}

No comments:

Post a Comment