import java.io.*;
import java.util.StringTokenizer;

// This class will read a file of inetegers and place them in an array.
class FileReader
{

    private BufferedReader input;

    private boolean fileIsOver;
    
    int [] data;


    // This method will open a file called inputFile. It will read first number
    // which is assumed to be the number of numbers in the rest of the file.
    // Then it will read all subsequent numbers and place them in an array
    // which is returned to the caller.
    // The assumption is that all numbers are integers.
    // If the file is not in the correct format, a null array will be returned.
    public int[] readFile(String inputFile)
    {
        String nextLine;
        int fileSize = 0;
        StringTokenizer st;
        

        //open the file named inputFile
        try{
            input = new BufferedReader( new InputStreamReader ( new FileInputStream( inputFile ) ) );
        }
        catch (IOException e){
           return null;
        }

        //read number of lines in file
        try
        {
            if ((nextLine = input.readLine())!= null)
            {
                st = new StringTokenizer(nextLine);
                if (st != null)
                {
                    if (st.hasMoreTokens())
                    fileSize = Integer.parseInt( st.nextToken() );
                }
            }
            else fileSize = 0;
        }
        catch(EOFException e){
        }
        catch(IOException e){
        }
        catch(NumberFormatException e){
        }
        
        // create the array of the right size
        if ( fileSize > 0 )
            data = new int[ fileSize ];
        else 
            return null;
        
        for ( int i = 0; i < fileSize; i++)
        {
            try
            {
                if ((nextLine = input.readLine())!= null)
                {
                    st = new StringTokenizer(nextLine);
                    if (st != null)
                    {
                        if (st.hasMoreTokens())
                            data[i] = Integer.parseInt( st.nextToken() );
                        else data = null;
                    }
                }
                else 
                {
                    data = null;
                }

            }
            catch(EOFException e){
            }
            catch(IOException e){
            }
            catch(NumberFormatException e){
            }
            
            if ( data == null)
                break;
        }
        



        // close the file
        try{
            input.close();
        }
        catch( IOException e){
        }
        
        return data;

    }

}
