Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.*;
  4. import java.util.ArrayList;
  5. import java.util.HashSet;
  6. import java.util.List;
  7.  
  8. public class Main {
  9.  
  10.     public static boolean isListContainsEmail(String email, HashSet<String> uniq) {
  11.         for (String item: uniq) {
  12.             if (email.equals(item.split(";")[0])) {
  13.                 return true;
  14.             }
  15.         }
  16.  
  17.         return false;
  18.     }
  19.  
  20.     public static void main(String[] args) throws IOException {
  21.         String currentPath = System.getProperty("user.dir");
  22.        
  23.         String inputPath = currentPath.concat("\\input.txt");
  24.         HashSet<String> uniqueLines = new HashSet<>();
  25.  
  26.         try (BufferedReader bufferedReader = new BufferedReader(new FileReader(inputPath))) {
  27.             String readLine;
  28.  
  29.             while ((readLine = bufferedReader.readLine()) != null) {
  30.                 String email = readLine.split(";")[0];
  31.  
  32.                 if (!isListContainsEmail(email, uniqueLines)) {
  33.                     uniqueLines.add(readLine);
  34.                 }
  35.             }
  36.         } catch (IOException e) {
  37.             e.printStackTrace();
  38.         }
  39.        
  40.         String output = currentPath.concat("\\output_app.txt");
  41.        
  42.         BufferedWriter writer = new BufferedWriter(new FileWriter(output, false));
  43.  
  44.         for (String word: uniqueLines) {
  45.             writer.write(word);
  46.             writer.newLine();
  47.         }
  48.         writer.close();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement