try { Stream<String> stringStream = Files.lines(path, StandardCharsets.UTF_8); stringStream.forEach((String e) -> { if (e.contains("12")) { System.out.println(path); break; // как остановить работу если нашёл нужное } }); } catch (IOException e) { e.printStackTrace(); } I can not understand how to use filter.findfirst show on my example