![]() |
![]() |
![]() |
![]() |
![]() |
|
The catch blocks in the following
version of the
readMovieFile program, which you saw in a previous incarnation in
Segment 600, announce where and why an exception is
caught:
import java.io.*;
import java.util.*;
public class Auxiliaries {
public static Vector readMovieFile(String fileName) {
Vector v = new Vector();
try {
FileInputStream stream = new FileInputStream(fileName);
if (stream == null) {return null;}
InputStreamReader reader = new InputStreamReader(stream);
StreamTokenizer tokens = new StreamTokenizer(reader);
tokens.quoteChar((int) '"');
tokens.eolIsSignificant(true);
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();
}
catch (FileNotFoundException e) {System.out.println(e);}
catch (IOException e) {System.out.println(e);}
return v;
}
}
This version of the Auxiliaries definition, which contains a
definition of readMovieFile, serves up to Segment 45, where
the FileInputStream mechanism is replaced by a more general
mechanism that is better suited to handling files accessed via a network
browser.