Home Segments Top Top Previous Next

548: Mainline

The following program illustrates the approach that creates the array in the called method. In this version, the file name is passed from main to readData:

import java.io.*; 
public class Demonstrate { 
 public static void main(String argv[]) throws IOException { 
  Movie mainArray [] = Auxiliaries.readData("input.data");  
  // Remainder as in Segment 543 
 } 
} 

import java.io.*; 
public class Auxiliaries { 
 public static Movie[] readData(String fileName) throws IOException { 
  FileInputStream stream = new FileInputStream(fileName);  
  InputStreamReader reader = new InputStreamReader(stream); 
  StreamTokenizer tokens = new StreamTokenizer(reader); 
  Movie movies [] = new Movie [100];  
  int movieCounter = 0;  
  // While loop as in Segment 544 
  stream.close();  
  return movies;  
 } 
}