import java.io.*; public class SearchLib { public static void main(String a[]) { int i; // create an array with space for 100 Book objects Book lib[] = new Book[100]; // ---------------------------------------------------------------- try { // open the text file book.txt // (create a BufferedReader object) BufferedReader file = new BufferedReader(new FileReader("book.txt")); // read three Book records (each having three lines) for (i = 0; i < 3; i++) { String title = file.readLine(); // first line -> title String author = file.readLine(); // second line -> author String year = file.readLine(); // third line -> year // watch out: you need to transform the String year // into an int, so the constructor is happy lib[i] = new Book(title, author, Integer.parseInt(year)); } // close the file file.close(); // ---------------------------------------------------------------- } catch (Exception e) { System.out.println("something is wrong"); System.exit(1); } // just to check, I want to print out the three titles for (i = 0; i < 3; i++) { System.out.println(lib[i].getTitle()); } } }