Monday, April 30, 2018

Compare two file content if it is equal or not !!

Using FileUtils:
  1. import java.io.File;
  2. import org.apache.commons.io.FileUtils;

  3. public class CompareFileContent {
  4. public static void main(String[] args) throws Exception {
  5. File file1 = new File("D:\\data.txt");
  6. File file2 = new File("D:\\data1.txt");
  7. boolean isEqual = FileUtils.contentEquals(file1, file2);
  8. System.out.println(isEqual == true ? "equal" : "not equal");
  9. }
  10. }
Output:
equal

data.txt - file:
Hi guys !!
This is Ishaan from India.
and I'm reading the data from a text file line by line using BufferedReader.
Isn't it interesting !! to read the data from a file line by line 
irrespective of amount of data that a file is having.

data1.txt - file:
Hi guys !!
This is Ishaan from India.
and I'm reading the data from a text file line by line using BufferedReader.
Isn't it interesting !! to read the data from a file line by line 
irrespective of amount of data that a file is having.

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...