Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.util.ArrayList;
- import java.util.HashSet;
- import java.util.List;
- public class Main {
- public static boolean isListContainsEmail(String email, HashSet<String> uniq) {
- for (String item: uniq) {
- if (email.equals(item.split(";")[0])) {
- return true;
- }
- }
- return false;
- }
- public static void main(String[] args) throws IOException {
- String currentPath = System.getProperty("user.dir");
- String inputPath = currentPath.concat("\\input.txt");
- HashSet<String> uniqueLines = new HashSet<>();
- try (BufferedReader bufferedReader = new BufferedReader(new FileReader(inputPath))) {
- String readLine;
- while ((readLine = bufferedReader.readLine()) != null) {
- String email = readLine.split(";")[0];
- if (!isListContainsEmail(email, uniqueLines)) {
- uniqueLines.add(readLine);
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- String output = currentPath.concat("\\output_app.txt");
- BufferedWriter writer = new BufferedWriter(new FileWriter(output, false));
- for (String word: uniqueLines) {
- writer.write(word);
- writer.newLine();
- }
- writer.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement