It seems to pass the tests I do, but it wont verify. On the last condition it says "Consider the fact that the words list can have an arbitrary number of words". I've tried it with longer lines and it still seems to work, so unsure what it means?
package com.codegym.task.task19.task1922;
import sun.java2d.InvalidPipeException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Searching for the right lines
*/
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 IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
//String file = "C:\\Users\\boris\\Desktop\\test.txt";
String file = reader.readLine();
reader.close();
FileReader fr = new FileReader(file);
BufferedReader br = new BufferedReader(fr);
String line = null;
int wordcount = 0;
List<String> list = new ArrayList<>();
while ((line = br.readLine()) != null) {
String[] arr = line.split(" ");
for (String s: arr) {
if(s.matches(words.get(0)) || s.matches(words.get(1)) || s.matches(words.get(2))){
wordcount++;
}
}
if (wordcount == 2) {
System.out.println(line);
}
wordcount = 0;
}
/* for (String str: list) {
System.out.println(str);
} */
fr.close();
br.close();
}
}