import java.util.Scanner;
import java.util.Iterator;
import java.io.*;

public class Lines implements Iterator<String>, Iterable<String> {
   
private Scanner scanner;
   
public Lines(Scanner scanner) {
       
this.scanner = scanner;
   
}
   
public boolean hasNext() {
       
return scanner.hasNextLine();
   
}
   
public String next() {
       
return scanner.nextLine();
   
}
   
public void remove() {
       
throw new UnsupportedOperationException();
   
}
   
public Iterator<String> iterator() {
       
return this;
   
}
   
   
public static void main(String[] args) {
       
// Get filename and search string from stdin
       
Scanner input = new Scanner(System.in);
        System.out.print
("Enter filename      : ");
        String path = input.nextLine
();
        System.out.print
("Enter search string : ");
        String searchFor = input.nextLine
();

       
// Search every line in the file for the search string
       
try {
           
Scanner file = new Scanner(new File(path));
           
for(String line : new Lines(file)) {
               
if(line.contains(searchFor)) {
                   
System.out.println(line);
               
}
            }
        }
catch(FileNotFoundException e) {
           
System.out.println("Could not find " + path);
       
}
    }
}