The code is quite obvious and works ok. Why it does not pass?
package com.codegym.task.task17.task1721;
import javax.imageio.IIOException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
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<>();
private static String fileName1;
private static String fileName2;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
fileName1 = sc.nextLine();
fileName2 = sc.nextLine();
sc.close();
Solution solution = new Solution();
try {
solution.joinData();
} catch (IOException e) {
if (e instanceof CorruptedDataException)
System.out.println("Not all lines present");
else e.printStackTrace();
}
//System.out.println(allLines);
}
public void joinData() throws IOException {
Scanner readFile = new Scanner(Paths.get(fileName1));
while (readFile.hasNextLine()) {
allLines.add(readFile.nextLine());
}
//System.out.println(allLines);
readFile.close();
Scanner readFileForRemove = new Scanner(new File(fileName2));
while (readFileForRemove.hasNextLine()) linesForRemoval.add(readFileForRemove.nextLine());
readFileForRemove.close();
//System.out.println(linesForRemoval);
if (allLines.containsAll(linesForRemoval)) allLines.removeAll(linesForRemoval);
else {
allLines.clear();
throw new CorruptedDataException();
}
}
}