I've made an isDebugging boolean variable, so I could check what is going on in the code.
I made two text files list and remove, here are those and the output:
package com.codegym.task.task17.task1721;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*
Transactionality
*/
public class Solution {
public static List<String> allLines = new ArrayList<>();
public static List<String> linesForRemoval = new ArrayList<>();
public static boolean isDebugging = false;
public static void main(String[] args) {
Solution sol = new Solution();
try {
sol.joinData();
}
catch (CorruptedDataException e) {
e.printStackTrace();
}
}
public void joinData() throws CorruptedDataException {
Scanner scanner = new Scanner(System.in);
if (isDebugging) {
input(allLines, "/Users/dusihome/Documents/CodeGymTasks/2.JavaCore/src/com/codegym/task/task17/task1721/list");
input(linesForRemoval, "/Users/dusihome/Documents/CodeGymTasks/2.JavaCore/src/com/codegym/task/task17/task1721/remove");
}
else {
input(allLines, scanner.nextLine());
input(linesForRemoval, scanner.nextLine());
}
// allLines.forEach(System.out::println);
if (allLines.containsAll(linesForRemoval))
allLines.removeAll(linesForRemoval);
else {
allLines.clear();
throw new CorruptedDataException();
}
// System.out.println();
// allLines.forEach(System.out::println);
}
public static void input(List<String> list, String source) {
try {
BufferedReader reader = new BufferedReader(new FileReader(source));
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
reader.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}