Created
June 11, 2015 12:57
-
-
Save vladholubiev/e33db2805b77ba6bfb5e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package ua.samosfator; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import java.io.PrintWriter; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.util.ArrayList; | |
| import java.util.List; | |
| import java.util.stream.Collectors; | |
| public class Main { | |
| public static void main(String[] args) throws Exception { | |
| final List<String> lines = new ArrayList<>(); | |
| String result = ""; | |
| Files.walk(Paths.get("")).forEach(filePath -> { | |
| if (Files.isRegularFile(filePath)) { | |
| String[] fileNameParts = filePath.toString().split("\\."); | |
| String fileExtension = fileNameParts[fileNameParts.length - 1]; | |
| if (fileExtension.equals("txt")) { | |
| try { | |
| List<String> fileLines = Files.readAllLines(filePath); | |
| fileLines = fileLines.stream() | |
| .filter(line -> line.contains("From: ") || line.contains("E-mail")) | |
| .collect(Collectors.toList()); | |
| lines.addAll(fileLines); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| } | |
| } | |
| } | |
| }); | |
| for (String line : lines) { | |
| String[] parts = line.split(": "); // "From", "[email protected]" | |
| parts[0] = parts[0].trim(); | |
| parts[1] = parts[1].trim(); | |
| if (parts[0].contains("From")) { | |
| if (!parts[1].contains("main-hosting.eu")) { | |
| result += parts[1] + ":"; | |
| } | |
| } | |
| if (parts[0].contains("E-mail")) { | |
| if (parts[0].length() < 10) { | |
| result += parts[1] + ":"; | |
| } else { | |
| result += parts[1] + System.lineSeparator(); | |
| } | |
| } | |
| } | |
| PrintWriter printWriter = new PrintWriter(new File("output.txt")); | |
| printWriter.println(result); | |
| printWriter.flush(); | |
| printWriter.close(); | |
| System.out.println(result); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment