import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class FooBarMainEntry { public static void main(String[] args) { String done = FileHelper.readFileToString(""); List<String> all = FileHelper.readFileToStringList(""); List<String> notDone = all.stream() .map(String::trim) .filter(line ->{return !done.contains(line);} ) .collect(Collectors.toList()); FileHelper.overWriteStringListToFile("", notDone); } } class FileHelper { public static String readFileToString(String filePath){ String content = ""; try{ content = new String ( Files.readAllBytes( Paths.get(filePath) ) ); } catch (IOException e){ e.printStackTrace(); } return content; } public static List<String> readFileToStringList(String filePath) { List<String> result=new ArrayList<String>(); try (Stream<String> stream = Files.lines( Paths.get(filePath), StandardCharsets.UTF_8)){ stream.forEach(s -> result.add(s)); } catch (IOException e){ e.printStackTrace(); } return result; } public static void overWriteStringToFile(String filePath, String content) { try{ BufferedWriter writer = new BufferedWriter(new FileWriter(filePath)); writer.write(content); writer.close(); } catch(Exception e) { e.printStackTrace(); } } public static void appendStringToFile(String filePath, String content) { try{ BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true)); writer.append(content); writer.close(); } catch(Exception e) { e.printStackTrace(); } } public static void overWriteStringListToFile(String filePath, List<String> content) { if(content.isEmpty()) { return; } try{ BufferedWriter writer = new BufferedWriter(new FileWriter(filePath)); writer.write(content.get(0)); writer.append("\n"); for(int i =1; i< content.size()-1;++i) { writer.append(content.get(i)); writer.append("\n"); } writer.append(content.get(content.size()-1)); writer.close(); } catch(Exception e) { e.printStackTrace(); } } public static void appendStringListToFile(String filePath, List<String> content) { if(content.isEmpty()) { return; } try{ BufferedWriter writer = new BufferedWriter(new FileWriter(filePath, true)); for(int i =0; i< content.size()-1;++i) { writer.append(content.get(i)); writer.append("\n"); } writer.append(content.get(content.size()-1)); writer.close(); } catch(Exception e) { e.printStackTrace(); } } }