В консоль выводит
SAME строка1
REMOVED строка2
SAME строка3
REMOVED строка4
SAME строка5
ADDED строка0
SAME строка1
REMOVED строка2
SAME строка3
ADDED строка4
SAME строка5
REMOVED строка0
package com.javarush.task.task19.task1916;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Отслеживаем изменения
*/
public class Solution {
public static List<LineItem> lines = new ArrayList<LineItem>();
public static void main(String[] args) throws IOException {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader file1 = new BufferedReader(new FileReader(reader.readLine()));
BufferedReader file2 = new BufferedReader(new FileReader(reader.readLine()));){
/*try(BufferedReader file1 = new BufferedReader(new FileReader("D:\\Desktop\\TestCodeWithFile\\file1.txt"));
BufferedReader file2 = new BufferedReader(new FileReader("D:\\Desktop\\TestCodeWithFile\\file2.txt"));){*/
while (file1.ready()){
String s1 = file1.readLine();
String s2 = file2.readLine();
if(s1.equals(s2)){
lines.add(new LineItem(Type.SAME, s1));
} else if(s2.contains(s1)){
lines.add(new LineItem(Type.ADDED, s2));
} else {
lines.add(new LineItem(Type.REMOVED, s1));
}
}
for (int i = 0; i< lines.size(); i++){
System.out.println(lines.get(i).type + " " + lines.get(i).line);
}
}
}
public static enum Type {
ADDED, //добавлена новая строка
REMOVED, //удалена строка
SAME //без изменений
}
public static class LineItem {
public Type type;
public String line;
public LineItem(Type type, String line) {
this.type = type;
this.line = line;
}
}
}