import java.io.*; class GrepA { public static void main(String[] args) throws IOException { String phrase = args[0]; String filename = args[1]; try { // FileNotFoundException FileReader fr = new FileReader(filename); BufferedReader br = new BufferedReader(fr); String line; while ((line = br.readLine()) != null) { if (line.equals(phrase)) System.out.println(line); } } catch (FileNotFoundException e) { System.out.println("File not found!"); } } } /* if (line == phrase) { // WRONG! // true only if line and phrase // points to the same String object } */