last condition is not satisfying. :(
package com.codegym.task.task19.task1922;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Searching for the right lines
1. The Solution class must have a public static List<String> field called words that is initialized immediately.
2. The Solution class must have a static block that adds three or more words to the words list.
3. The program must read the file name from the console (use BufferedReader).
4. The BufferedReader used for reading input from the console must be closed after use.
5. The program must read the file's contents (use FileReader).
6. The file input stream (FileReader) must be closed.
7. The program should display all of the file's lines that contain only 2 words in the words list.
*/
public class Solution {
public static List<String> words = new ArrayList<>();
static {
words.add("file");
words.add("view");
words.add("In");
}
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String file = br.readLine();
BufferedReader br1 = new BufferedReader(new FileReader(file));
br.close();
String s ;
//StringBuilder builder = new StringBuilder();
while (br1.ready()) {
s = br1.readLine();
String[] str = s.split(" ");
for (String s1 : str) {
for (String word : words) {
if (s1.matches(word)) {
System.out.println(s);
}
}
}
}
br1.close();
}
}