Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Compare two files PDF and summaries in Java

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Compare two files PDF and summaries in Java

    I am new in Java, I have written code to compare two files of data in Java but that is only working for 1 line not for all lines or whole file. Below is my code:

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;

    public class CompareTextFiles {

    public static void main(String[] args) throws IOException {
    BufferedReader reader1 = new BufferedReader(new FileReader("D:/Data/file1.docx"));
    BufferedReader reader2 = new BufferedReader(new FileReader("D:/Data/file2.docx"));
    String line1 = reader1.readLine();
    String line2 = reader2.readLine();
    boolean areEqual = true;
    int lineNum = 1;
    while (line1 != null || line2 != null) {
    if (line1 == null || line2 == null) {
    areEqual = false;
    break;
    } else if (!line1.equalsIgnoreCase(line2)) {
    areEqual = false;
    break;
    }
    line1 = reader1.readLine();
    line2 = reader2.readLine();
    lineNum++;
    }
    if (areEqual) {
    System.out.println("Two files have same content.");
    } else {
    System.out.println("Two files have different content. They differ at line " + lineNum);
    System.out.println("File1 has " + line1 + " and File2 has " + line2 + " at line " + lineNum);
    }
    reader1.close();
    reader2.close();
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Compare two files PDF and summaries in Java

    The contents of doc files is not text that can be read and understand without conversion.

    Also posted at: https://coderanch.com/t/691647/java/...s-Java#3246783
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. compare 2 PDF file and write summary of that in JAVA
    By rahulsinghindia15 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 10th, 2018, 02:00 PM
  2. how to compare the large text files ?
    By vamshi in forum Java Theory & Questions
    Replies: 4
    Last Post: July 14th, 2013, 06:13 AM
  3. Replies: 2
    Last Post: July 9th, 2013, 09:51 PM
  4. Java API to compare two files
    By Shakthi in forum Java Theory & Questions
    Replies: 16
    Last Post: August 22nd, 2012, 09:51 AM

Tags for this Thread