import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class SearchAndPrint { public static void main(String[] args) { String textToSearch = args[0]; String filename = args[1]; try { searchAndPrint(textToSearch, filename); } catch(IOException e) { System.out.println("There's an IO issue!"); } } public static void searchAndPrint(String textToSearch, String filename) throws IOException { try (BufferedReader br = new BufferedReader(new FileReader(filename))) { String line = null; int lnNum = 1; int cnt = 0; while ((line = br.readLine()) != null) { if(line.contains(textToSearch)) { System.out.println(lnNum + ":" + line); cnt++; } lnNum++; } System.out.println("Summary: " + cnt + " word(s) are found."); } } }