Last active
August 28, 2017 11:54
-
-
Save ihopeudie/b787002e2dbe5af80a3e2952c79f8351 to your computer and use it in GitHub Desktop.
Транзакционность javarush
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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