-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPrinter.java
51 lines (42 loc) · 1.27 KB
/
Printer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author kdost
*/
public class Printer {
private File f;
private Scanner reader;
private List<String> fileRead;
public Printer(String fileName) throws Exception {
this.f = new File(fileName);
this.reader = new Scanner(this.f, "UTF-8");
this.fileRead = new ArrayList<String>();
while (this.reader.hasNextLine()) {
this.fileRead.add(this.reader.nextLine());
}
// this.fileRead.split("\n");
// System.out.println(this.fileRead);
}
public void printLinesWhichContain(String word) {
if (word.isEmpty()) {
for (int i = 0; i < this.fileRead.size(); i++) {
System.out.println(this.fileRead.get(i));
}
} else {
for (int j = 0; j < this.fileRead.size(); j++) {
if (this.fileRead.get(j).contains(word)) {
System.out.println(this.fileRead.get(j));
}
}
}
}
}
}