Это из за кодировки?
Если я создают файл в utf -8 у меня перед словом возникает символ какой то
если я делаю так
import java.nio.charset.Charset;
BufferedReader readfile = new BufferedReader(new FileReader(namefile, Charset.forName("windows-1251")) );
вроде все работает
package com.javarush.task.task19.task1922;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Ищем нужные строки
*/
public class Solution {
public static List<String> words = new ArrayList<String>();
static {
words.add("файл");
words.add("вид");
words.add("В");
}
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String namefile = reader.readLine();
// String namefile = "4.txt";
BufferedReader readfile = new BufferedReader(new FileReader(namefile) );
List<String> filestring = new ArrayList<>();
while (readfile.ready()) {
filestring.add(readfile.readLine());
}
reader.close();
readfile.close();
int count1=0;
int count2=0;
int count3=0;
for (int i = 0; i < filestring.size(); i++) {
String[] test = filestring.get(i).split(" ");
for (int j=0;j<test.length;j++) {
if (test[j].matches("(\\p{IsPunctuation})?"+words.get(0)+"(\\p{IsPunctuation})?")) count1=1;
if (test[j].matches("(\\p{IsPunctuation})?"+words.get(1)+"(\\p{IsPunctuation})?")) count2=1;
if (test[j].matches("(\\p{IsPunctuation})?"+words.get(2)+"(\\p{IsPunctuation})?")) count3=1;
}
if (count1+count2+count3==2) System.out.println(filestring.get(i));
count1=0;
count2=0;
count3=0;
}
}
}