In the below example, I am able to identify the overall changes. But I am not able to get the string which has been edited or added separately. Is there any algorithm/approach to detect whether a string is edited or added or deleted within a file? I have tried java File Watcher, but that only detects a file, whether the file has been edited or created or deleted or modified any content within the file or not. It does not provide the changes which has been performed within the file.
diffFiles
function just checks whether a string is matching in both files or not. I have made a copy of the base file and checking the differences:
public HashMap<String, Integer> diffFiles(List<String> firstFileContent, List<String> secondFileContent) throws IOException {
Integer count = 0;
final HashMap<String, Integer> diff = new HashMap<String, Integer>();
for (final String line : firstFileContent) {
count += 1;
if (!secondFileContent.contains(line)) {
diff.put(line, count);
}
}
return diff;
}
I want to individually identify the strings within the file whether it has been edited or added within the file