I assume I am failing for writing my own shoddy method (fileAdd) and trying to be clever. But I'm not sure why it doesn't work. And my brain has been pummeled by these tasks already, so I'm gonna need some help on this one.
package com.codegym.task.task17.task1721;
import java.io.FileReader;
import java.io.IOException;
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, fileName2;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
fileName1 = sc.nextLine();
fileName2 = sc.nextLine();
sc.close();
Solution solution = new Solution();
solution.joinData();
}
public void joinData() throws CorruptedDataException {
allLines = fileAdd(fileName1);
linesForRemoval = fileAdd(fileName2);
if (allLines.containsAll(linesForRemoval)) {
allLines.removeAll(linesForRemoval);
}
else {
allLines.clear();
throw new CorruptedDataException();
}
}
public static List<String> fileAdd (String file) {
List<String> result = new ArrayList<>();
try {
FileReader f = new FileReader(file);
StringBuffer sb = new StringBuffer();
while (f.ready()) {
char c = (char) f.read();
if (c == '\n') {
result.add(sb.toString());
sb = new StringBuffer();
}
}
if (sb.length() > 0)
result.add(sb.toString());
}
catch (IOException e) {}
return result;
}
}