/** Given as command line parameter the name of a file
  * containing integers, it reads them into an ArrayList.
  * Beware that lines in the file may contain zero or more integers per
  * line, separated by spaces.
  */

import java.io.*;
import java.util.*;

public class ReadInts {
    public static void main(String[] args) {
	ArrayList nums = new ArrayList();
	try {
	    BufferedReader rd = new BufferedReader(new FileReader(args[0]));
	    String aline;
	    while ((aline = rd.readLine()) != null) {
		StringTokenizer tk = new StringTokenizer(aline);
		while (tk.hasMoreTokens()) {
		    int k = Integer.parseInt((String)tk.nextToken());
		    nums.add(new Integer(k));
		}
	    }
	    rd.close();
        } catch (FileNotFoundException e) {
	    System.out.println("Sorry, cannot open file " + args[0]);
	} catch (IOException e) {
	    System.out.println(e.toString());
	}
	System.out.println("The content of file " + args[0] + " is:");
	Object[] nn = nums.toArray();
	for (int k = 0; k < nn.length; k++) {
	    System.out.println(((Integer)nn[k]).intValue());
	}
    }
}
