Помогите разобраться, данные считываю, список очищаю, что не так не пойму
package com.javarush.task.task17.task1721;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.*;
/*
Транзакционность
*/
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)
{
Solution solution = new Solution();
try
{
solution.joinData();
}
catch (CorruptedDataException e)
{
System.out.println("Ashibka v maine bro");
}
catch (IOException e)
{
System.out.println("Ashibka IO bro");
}
}
public void joinData() throws CorruptedDataException, IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter is two files name");
String path = reader.readLine();
String path2 = reader.readLine();
// Path file1 = Files.createFile(Path.of(path));
// Path file2 = Files.createFile(Path.of(path2));
File file1 = new File(path);
File file2 = new File(path2);
Scanner scanner1 = new Scanner(file1);
Scanner scanner2 = new Scanner(file2);
while (scanner1.hasNextLine())
{
allLines.add(scanner1.nextLine());
}
while (scanner2.hasNextLine())
{
forRemoveLines.add(scanner2.nextLine());
}
for (String s : forRemoveLines)
{
if (!allLines.contains(s))
{
allLines.clear();
throw new CorruptedDataException();
}
}
for (String s : forRemoveLines)
{
allLines.remove(s);
}
reader.close();
scanner1.close();
scanner2.close();
}
}