I have two text files and I want to compare the contents of text files using java.
For example First file e1.txt has the content "hello this is india" , and another e2.txt contents "hello this is usa". I want the output should be the text which is not similer in both files(here output should be india or usa).
Problem which I was facing here is that java IO method reads line by line so in this case no output will be given(both lines are different), also white spaces should be ignored. I will be very much thankful if anyone will help me in this problem.
Here is my Code :
public void fh() throws FileNotFoundException, IOException{
File f1=new File("C:\\\\Users\\\\Ramveer\\\\Desktop\\\\idrbt Project\\\\e1.txt");
File f2=new File("C:\\\\Users\\\\Ramveer\\\\Desktop\\\\idrbt Project\\\\e2.txt");
FileInputStream fi1=new FileInputStream(f1);
FileInputStream fi2=new FileInputStream(f2);
DataInputStream di1=new DataInputStream(fi1);
BufferedReader br1=new BufferedReader(new InputStreamReader(di1));
DataInputStream di2=new DataInputStream(fi2);
BufferedReader br2=new BufferedReader(new InputStreamReader(di2));
String s1, s2;
while ((s1=br1.readLine())!=null && (s2=br2.toString())!=null)
{
if(!s1.equals(s2)){
System.out.println(s1);
}
}
}
java.util.Scanner