// This program is an example of file processing. // It takes in a search string that we use to // to search through the files in a list of the // top 250 movies on IMDB. // // If it finds the search string in the title of a // movie, it prints out some data to a file // // This is as far as we got in class: it still could // use some token based processing. import java.util.*; import java.io.*; public class Imdb { public static void main(String[] args) throws FileNotFoundException { Scanner console = new Scanner(System.in); Scanner input = new Scanner(new File("imdb.txt")); System.out.print("Type in a search string: "); String search = console.next(); System.out.print("Type in an output filename: "); String outputFile = console.next(); // creating a PrintStream creates the file if it doesn't // exist, or overwrites if it already existed PrintStream output = new PrintStream(new File(outputFile)); // line based search throuh the file: while(input.hasNextLine()) { String line = input.nextLine(); // check if the line contains the search value if (line.toLowerCase().contains(search.toLowerCase())) { output.println("line = " + line); } } } }