Really unsure why all those conditions are failing
Edit: I've moved lines 44/45 and 49/50 out of the loops. Still failing
package com.codegym.task.task17.task1721;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Transactionality
*/
public class Solution {
public static List<String> allLines = new ArrayList<>();
public static List<String> linesForRemoval = new ArrayList<>();
public static void main(String[] args) {
Solution solution = new Solution();
try {
solution.joinData();
} catch (IOException e) {
e.printStackTrace();
}
}
public void joinData() throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fileName1 = reader.readLine();
String fileName2 = reader.readLine();
FileInputStream fileInputStream1 = new FileInputStream(fileName1);
FileInputStream fileInputStream2 = new FileInputStream(fileName2);
BufferedReader fileReader1 = new BufferedReader(new InputStreamReader(fileInputStream1));
BufferedReader fileReader2 = new BufferedReader(new InputStreamReader(fileInputStream2));
String s;
while ((s = fileReader1.readLine())!=null) {
allLines.add(s);
fileInputStream1.close();
fileReader1.close();
}
while ((s = fileReader2.readLine())!=null) {
linesForRemoval.add(s);
fileInputStream2.close();
fileReader2.close();
}
reader.close();
int count = 0;
for (int i =0; i<linesForRemoval.size(); i++){
if (allLines.contains(linesForRemoval.get(i)))
count++;
}
if (count == linesForRemoval.size()){
for (int i = 0; i<allLines.size(); i++){
for (int j =0; j<linesForRemoval.size(); j++){
if (allLines.get(i).equals(linesForRemoval.get(j))){
allLines.remove(i);
i--;
}
}
}
}
else {
allLines.clear();
throw new CorruptedDataException();
}
}
}