Skip to content

Instantly share code, notes, and snippets.

@ihopeudie
Last active August 28, 2017 11:54
Show Gist options
  • Save ihopeudie/b787002e2dbe5af80a3e2952c79f8351 to your computer and use it in GitHub Desktop.
Save ihopeudie/b787002e2dbe5af80a3e2952c79f8351 to your computer and use it in GitHub Desktop.
Транзакционность javarush
package com.javarush.task.task17.task1721;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
/*
Транзакционность javarush
*/
public class Solution {
public static List<String> allLines = new ArrayList<String>();
public static List<String> forRemoveLines = new ArrayList<String>();
public static List<String> readFile(String fileName) {
ArrayList<String> list = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(
new InputStreamReader(
new FileInputStream(fileName)));
String line;
while ((line = reader.readLine()) != null) {
list.add(line);
}
reader.close();
} catch (IOException e) {
}
return list;
}
public static void main(String[] args) throws CorruptedDataException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String fName1 = new String(),
fName2 = new String();
try {
fName1 = reader.readLine();
fName2 = reader.readLine();
reader.close();
}
catch (IOException e){
}
allLines = readFile(fName1);
forRemoveLines = readFile(fName2);
new Solution().joinData();
}
public void joinData () throws CorruptedDataException {
/*Важно отделить чтение файлов в мейн и в joinData вынести только работу со списком*/
if (allLines.containsAll(forRemoveLines)) allLines.removeAll(forRemoveLines);
else {
allLines.clear();
throw new CorruptedDataException();}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment