Is si because I use Scanner and I should use a bufferedReader? if so why?
And what is the difference between:
allLines.removeAll(linesForRemoval);
&&
linesForRemoval.clear(); ??
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 void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String filename1 = "";
String filename2 = "";
try {
filename1 = reader.readLine();
filename2 = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Scanner scanner = new Scanner(new File(filename1));
Scanner scanner2 = new Scanner(new FileReader(filename2));
String line;
while (!scanner.nextLine().isEmpty()) {
line = scanner.nextLine();
allLines.add(line);
}
while (!scanner2.nextLine().isEmpty()) {
line = scanner2.nextLine();
linesForRemoval.add(line);
}
reader.close();
scanner.close();
scanner2.close();
Solution solution = new Solution();
solution.joinData();
}
public void joinData() throws CorruptedDataException {
if (allLines.containsAll(linesForRemoval)) {
allLines.removeAll(linesForRemoval);//what is the difference with linesForRemoval.clear()
} else {
allLines.clear();
throw new CorruptedDataException();
}
}
}