Guest User

Untitled

a guest
Sep 23rd, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.04 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package filecompare;
  6.  
  7. import java.io.BufferedReader;
  8. import java.io.File;
  9. import java.io.FileReader;
  10. import java.io.IOException;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13.  
  14. /**
  15.  *
  16.  * @author Deinum
  17.  */
  18. public class FileCompare {
  19.  
  20.     /**
  21.      * @param args the command line arguments
  22.      */
  23.     public static void main(String[] args) throws IOException {
  24.             FileCompare compCore = new FileCompare();
  25.         long start = System.currentTimeMillis();
  26.                
  27.         List<Integer> templist = compCore.searchDuplicates(new File(
  28.                 "d:\\doppelte\\BVA.PG4.0913_doppelte"));
  29.  
  30.         for (Integer i : templist) {
  31.  
  32.             System.out.println("Doppelte Zeile: " + i);
  33.         }
  34.  
  35.         long ende = System.currentTimeMillis();
  36.         System.out.println(ende - start + " ms dauerte es");                
  37.                
  38.     }
  39.        
  40.     public List<Integer> searchDuplicates(File importFile) throws IOException {
  41.  
  42.         FileReader fread = new FileReader(importFile);
  43.  
  44.         BufferedReader read = new BufferedReader(fread);
  45.  
  46.         String currentSearch = null;
  47.  
  48.         int currentLine = 1;
  49.  
  50.         List<Integer> listofLines = new ArrayList<Integer>();
  51.  
  52.         while (read.ready()) {
  53.  
  54.             currentSearch = read.readLine();
  55.  
  56.             listofLines.addAll(getLinesofOccurrence(currentSearch, importFile,
  57.                     currentLine));
  58.  
  59.             currentLine++;
  60.  
  61.             System.out.println("Zeile: " + currentLine);
  62.  
  63.         }
  64.  
  65.         return listofLines;
  66.     }
  67.    
  68.    
  69.     private List<Integer> getLinesofOccurrence(String searchedLine,
  70.             File importFile, int lineIgnored) throws IOException {
  71.  
  72.         FileReader fread = new FileReader(importFile);
  73.         BufferedReader read = new BufferedReader(fread);
  74.  
  75.         List<Integer> listofLines = new ArrayList<Integer>();
  76.  
  77.         int currentLine = 1;
  78.  
  79.         while (read.ready()) {
  80.  
  81.             if (read.readLine().matches(searchedLine)
  82.                     & currentLine != lineIgnored) {
  83.  
  84.                 listofLines.add(currentLine);
  85.  
  86.             }
  87.  
  88.             currentLine++;
  89.  
  90.         }
  91.  
  92.         return listofLines;
  93.  
  94.     }
  95.    
  96.    
  97. }
Add Comment
Please, Sign In to add comment