You can get a Stream<String>
that matches the file lines using File.lines(Path)
(Java 8 or higher).
Your code should look like this:
File.lines(Paths.get("seu_arquivo.log"))
.filter(x -> x.contains("O caminho de rede não foi encontrado."))
.forEach(System.out::println);
If you want to put the line number together:
AtomicInteger a = new AtomicInteger(0);
File.lines(Paths.get("seu_arquivo.log"))
.map(linha -> a.incrementAndGet() + "|" + linha)
.filter(x -> x.contains("O caminho de rede não foi encontrado."))
.forEach(System.out::println);
This assumes that your encoding is UTF-8. If it is ISO-8859-1 or some other, use the method lines
overloaded who also receives a Charset
:
File.lines(Paths.get("seu_arquivo.log"), StandardCharsets.ISO_8859_1)
Hello Matheus, what you tried, can share your code?
– Ricardo Pontual
What is the format of LOG? After all there is no universal standard format for all logs.
– Guilherme Nascimento
It is a Windows Robocopy log file, understand as a normal . txt file. I tried some things I found on the internet, but I didn’t save any because I thought I’d take an idea from scratch and build a zero code, specific for what I need.
– Matheus Henrique
But the log was created by you or another program ?
– Isac
The log is created by Windows Robocopy: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy
– Matheus Henrique