Help!
package com.javarush.task.task17.task1721;
import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
/*
Транзакционность
*/
public class Solution {
public static List<String> allLines = new ArrayList<String>();
public static List<String> forRemoveLines = new ArrayList<String>();
public static void main(String[] args) throws IOException, InterruptedException {
Solution solution = new Solution();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String path1 = reader.readLine();
String path2 = reader.readLine();
Thread[] threads = readFiles(path1, path2);
threads[0].start();
threads[1].start();
threads[0].join();
threads[1].join();
solution.joinData();
}
public void joinData() throws CorruptedDataException {
if(allLines.equals(forRemoveLines)) {
allLines.clear();
} else {
allLines.clear();
throw new CorruptedDataException();
}
}
public static Thread[] readFiles(String path1, String path2) throws IOException {
Thread[] threads = new Thread[2];
Thread thread1 = new Thread(() -> {
try {
readering(path1, allLines);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
Thread thread2 = new Thread(() -> {
try {
readering(path2, forRemoveLines);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
});
threads[0] = thread1;
threads[1] = thread2;
return threads;
}
public static void readering(String path, List<String> list) throws FileNotFoundException {
BufferedReader reader1 = new BufferedReader(new FileReader(path));
try {
String line = reader1.readLine();
while (line != null) {
list.add(line);
line = reader1.readLine();
}
}catch (IOException exception) {
exception.printStackTrace();
}
}
}