Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package filecompare;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- /**
- *
- * @author Deinum
- */
- public class FileCompare {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws IOException {
- FileCompare compCore = new FileCompare();
- long start = System.currentTimeMillis();
- List<Integer> templist = compCore.searchDuplicates(new File(
- "d:\\doppelte\\BVA.PG4.0913_doppelte"));
- for (Integer i : templist) {
- System.out.println("Doppelte Zeile: " + i);
- }
- long ende = System.currentTimeMillis();
- System.out.println(ende - start + " ms dauerte es");
- }
- public List<Integer> searchDuplicates(File importFile) throws IOException {
- FileReader fread = new FileReader(importFile);
- BufferedReader read = new BufferedReader(fread);
- String currentSearch = null;
- int currentLine = 1;
- List<Integer> listofLines = new ArrayList<Integer>();
- while (read.ready()) {
- currentSearch = read.readLine();
- listofLines.addAll(getLinesofOccurrence(currentSearch, importFile,
- currentLine));
- currentLine++;
- System.out.println("Zeile: " + currentLine);
- }
- return listofLines;
- }
- private List<Integer> getLinesofOccurrence(String searchedLine,
- File importFile, int lineIgnored) throws IOException {
- FileReader fread = new FileReader(importFile);
- BufferedReader read = new BufferedReader(fread);
- List<Integer> listofLines = new ArrayList<Integer>();
- int currentLine = 1;
- while (read.ready()) {
- if (read.readLine().matches(searchedLine)
- & currentLine != lineIgnored) {
- listofLines.add(currentLine);
- }
- currentLine++;
- }
- return listofLines;
- }
- }
Add Comment
Please, Sign In to add comment