You can use the program in Segment 613 to read movie script, acting, and direction ratings from file. Then, in the following program, you can write overall movie ratings into another file:
import java.io.*; import java.util.*; public class Demonstrate { public static void main(String argv[]) throws IOException { FileOutputStream stream = new FileOutputStream("output.data"); PrintWriter writer = new PrintWriter(stream); Vector mainVector; mainVector = Auxiliaries.readMovieFile("input.data"); for (Iterator i = mainVector.iterator(); i.hasNext();) { writer.println(((Movie) i.next()).rating()); } writer.flush(); stream.close(); System.out.println("File written"); } } --- Data --- "Apocalypse Now" 4 7 3 "apnow.jpg" "Bedtime for Bonzo" 8 8 7 --- Result --- File written
Once the main
method is executed, the file, output.data
,
contains the following data:
14 23