Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.63 KB | None | 0 0
  1.     public class Printer {
  2.    
  3.         private File file;
  4.    
  5.         public Printer(String fileName) throws Exception {
  6.             this.file = new File(fileName);
  7.         }
  8.    
  9.         public void printLinesWhichContain(String word) {
  10.             Scanner reader = new Scanner(this.file);
  11.    
  12.             while (reader.hasNextLine()) {
  13.                 String line = reader.nextLine();
  14.                 if (word.equals("")) {
  15.                     System.out.println(line);
  16.                 } else if (line.contains(word)) {
  17.                     System.out.println(line);
  18.    
  19.                 }
  20.             }
  21.    
  22.         }
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement