Now, you can write the following movie-reading program, which captures movie names, ratings, and poster files, if any:
import java.io.*; import java.util.*; public class Demonstrate { public static void main(String argv[]) throws IOException { Vector mainVector; mainVector = Auxiliaries.readMovieFile("input.data"); for (Iterator i = mainVector.iterator(); i.hasNext();) { System.out.println(((Movie) i.next()).rating()); } } }
import java.io.*; import java.util.*; public class Auxiliaries { public static Vector readMovieFile(String fileName) throws IOException { FileInputStream stream = new FileInputStream(fileName); InputStreamReader reader = new InputStreamReader(stream); StreamTokenizer tokens = new StreamTokenizer(reader); tokens.quoteChar((int) '"'); tokens.eolIsSignificant(true); Vector v = new Vector(); while (tokens.nextToken() != tokens.TT_EOF) { String nameString = tokens.sval; tokens.nextToken(); int x = (int) tokens.nval; tokens.nextToken(); int y = (int) tokens.nval; tokens.nextToken(); int z = (int) tokens.nval; Movie m = (new Movie(x, y, z)); m.title = nameString; if (tokens.nextToken() == tokens.TT_EOL) {} else {m.poster = tokens.sval; tokens.nextToken();} v.addElement(m); } stream.close(); return v; } }