import java.io.*;
// ArrayExample is used to run the ArrayClass.
public class ArrayExample
{ public static void main (String [] args)
{
ArrayClass array
= new ArrayClass ();
array.readArray
();
array.displayArray
();
} // main method
} // class ArrayExample
/* ArrayClass gets a new array called list, reads strings into it from
a file and then displays the strings on the screen. */
class ArrayClass
{
private String [] list;
private int listSize;
final int maxSize = 10;
ArrayClass ()
{
list = new String
[maxSize];
listSize = 0;
} // constructor
// readArray opens the file, infile.txt, reads
numbers from it and stores them in the array, list.
public void readArray ()
{
try
{
BufferedReader infile = new BufferedReader (new InputStreamReader (new
FileInputStream ("infile.txt")));
String string = infile.readLine ();
while ((string != null) && (listSize < maxSize))
{
list [listSize] = string;
listSize ++;
string = infile.readLine ();
}
infile.close
();
} catch (IOException
e) {System.out.println ("File Error.");}
} // method readArray
public void displayArray ()
{
for (int count
= 0; count < listSize; count ++)
System.out.println (list [count]);
} // method displayArray
} // class ArrayClass