Код: Выделить всё
public class Main {
public static void main(String[] args) {
LogParser logParser = new LogParser(Paths.get("C:\\Users\\Admin\\IdeaProjects\\Exercise\\src\\com\\logs\\example.log"));
System.out.println(logParser.getNumberOfUniqueIPs(null, new Date()));
} }
< /code>
и метод в классе Logparser: < /p>
private void readLogs() {
System.out.println(logDir);
try (DirectoryStream
streamDir = Files.newDirectoryStream(logDir)) {
System.out.println("la");
for (Path path: streamDir) {
String[] lines = Files.lines(path).toArray(String[]::new);
SimpleDateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy");
for (String s: lines) {
String[] strs = s.split("\t");
String ip = strs[0];
String userName = strs[1];
Date date = null;
Event event = Event.valueOf(strs[3]);
Status status = Status.valueOf(strs[4]);
try {
date = dateFormat.parse(strs[2]);
} catch (ParseException ign) {}
LogEntity entity = new LogEntity(ip, userName, date, event, status);
entities.add(entity);
}
}
} catch (IOException ign) {ign.printStackTrace();}
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... ally-exist