Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Printer {
- private File file;
- public Printer(String fileName) throws Exception {
- this.file = new File(fileName);
- }
- public void printLinesWhichContain(String word) {
- Scanner reader = new Scanner(this.file);
- while (reader.hasNextLine()) {
- String line = reader.nextLine();
- if (word.equals("")) {
- System.out.println(line);
- } else if (line.contains(word)) {
- System.out.println(line);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement