Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

File 1 -------------------- File2 Write a program that compares two text files f

ID: 3671806 • Letter: F

Question

File 1

--------------------

File2

Write a program that compares two text files for equality. Print out any lines that are different along with the line number Include the following: File I/O Exception Handling using a Try/Catch Block Algorithm: Initial and Refined · Internal Documentation ·All prologue information The two external files Use the following two files: File1.txt and File2.txt. These files are included. I have also attached zip files containing them because sometimes the files are converted to HTML files when downloaded,

Explanation / Answer

import java.io.*;

public class CompareTextFiles {

public static void main(String args[]) throws Exception {

FileInputStream fstream1 = new FileInputStream("C:\File1.txt");
FileInputStream fstream2 = new FileInputStream("C:\File2.txt");

DataInputStream in1= new DataInputStream(fstream1);
DataInputStream in2= new DataInputStream(fstream2);

BufferedReader br1 = new BufferedReader(new InputStreamReader(in1));
BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));

String strLine1, strLine2;


while((strLine1 = br1.readLine()) != null && (strLine2 = br2.readLine()) != null){
if(!strLine1.equals(strLine2)){
System.out.println(strLine1);

}

}

}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote