/
elrdn
/
sber-java-hw
Обзор
Документация
Войти
/
elrdn
/
sber-java-hw
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/homeworks/task4/FileAnalyzer.java
47 строк
1 KB
Elraden
Выполнены задания 1-5
16 июл 2025, 23:08
16 июл 2025, 23:08
17fb121
Код
Авторство
О чём код?
package homeworks.task4; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class FileAnalyzer { private int lineCount = 0; private int maxLength = 0; private final List<String> longestLines = new ArrayList<>(); public void analyzeFile(String filePath) { try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) { String line; while ((line = reader.readLine()) != null) { lineCount++; int length = line.length(); if (length > maxLength) { maxLength = length; longestLines.clear(); longestLines.add(line); } else if (length == maxLength) { longestLines.add(line); } } } catch (IOException e) { System.out.println("Невозможно прочитать файл по пути: " + filePath); System.out.println(e.getMessage()); } } public int getLineCount() { return lineCount; } public int getMaxLength() { return maxLength; } public List<String> getLongestLines() { return new ArrayList<>(longestLines); } }