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 17 of 17

Thread: Java API to compare two files

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java API to compare two files

    Is there any Java API available to compare two files?
    I want to compare the following format of files
    -> Microsoft Office Word
    -> Microsoft Office Excel
    -> Microsoft Office PowerPoint


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

    Default Re: Java API to compare two files

    Is there any Java API available to compare two files?
    Not that I know of in the Java SE. Perhaps there is a third party package. Have you looked at Apache POI?

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java API to compare two files

    I want to compare the following format of files
    Do you wish to check if the files end in .doc, .xls etc?!
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java API to compare two files

    Define 'compare'

  5. #5
    Junior Member
    Join Date
    Aug 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Java API to compare two files

    I want to get the difference in the content between two files. The difference should be highligted in some color and it should be shown to the user.

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    Well, thanks God, i found some place, relevant to my poblem. Actually my problem is almost similar. What i want is:

    "Suppose there are two huge text files (say 100000 character each), is there any API or efficient algorithm that could compare for changes/differences between two files?"


    I will be very thankful to you, please let me know as soon as you can.


    Regards...

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java API to compare two files

    What does Google return for file compare or file differences?
    I've written some programs over the years to to that. Somebody must have one that they are proud of and want to share.

  8. #8
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Java API to compare two files

    I want to get the difference in the content between two files. The difference should be highligted in some color
    What would you expect as output from such an API if you compared two files which were made from the same content, but one saved with Microsoft Word 95 and the other with Microsoft Word 6.0?

    Suppose there are two huge text files (say 100000 character each),
    Do you want to see the differences between the files (like Meld : Home Page) or just get an indication of how different they are?

  9. #9
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Java API to compare two files

    I want to get the difference in the content between two files. The difference should be highligted in some color
    Doesn't technically answer my question. For word documents, there could be differences on the byte level, but not directly visible at the content level (see sean's post). Or there could be formatting differences, but not text differences...so, do you want to compare the bytes, formatting, content (I presume the latter)?

  10. #10
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    Well, i am asking for an API that could work like (Getting two files, compaing for the differences among text and output is like the differences of text between two files, as if you have used repository software, when you do Show differences, it shows you difference between two versions and tell highlight where difference lies). That's what i am asking. Please let me know.

  11. #11
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    Quote Originally Posted by Sean4u View Post
    What would you expect as output from such an API if you compared two files which were made from the same content, but one saved with Microsoft Word 95 and the other with Microsoft Word 6.0?


    Do you want to see the differences between the files (like Meld : Home Page) or just get an indication of how different they are?
    Yeah like Meld one.... But i want to what Java API they used if it's Java based

  12. #12
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Java API to compare two files

    As far as I know there is no standard API for this as there is no standard way to define "different". Consider 2 files.

    File 1

    aaa
    bbb
    ccc
    ddd

    File 2

    zzz
    aaa
    bbb
    ccc
    ddd

    How do you determine the differences? I can quickly say that the only differnce is the second file has zzz at the beginning. But if you were to compare the files line by line then it would highlight that every line is different (aaa != zzz, bbb != aaa, etc). Plus what do you do when with the last line in the second file as there is no line in the first file to compare it to?
    Improving the world one idiot at a time!

  13. #13
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    Junky: Did you use SVN or VSS?
    Last edited by Mr.777; August 11th, 2011 at 03:02 AM.

  14. #14
    Super Moderator Sean4u's Avatar
    Join Date
    Jul 2011
    Location
    Tavistock, UK
    Posts
    637
    Thanks
    5
    Thanked 103 Times in 93 Posts

    Default Re: Java API to compare two files

    If you want to compare the text from two files saved in a (potentially different version of a) proprietary format, then you need something that understands the proprietary format - you can exclude all text-based comparison software. There's a thread at stackoverflow which mentions one or two of what I expect would be a very few options:

    http://www.google.com/search?q=java%...20word%20files
    Is there any Java API available to compare two microsoft word documents? - Stack Overflow

    It's a much more complicated task than text comparison, you might have to do a lot of work yourself to get something that works the way you want it for all your use cases.

  15. The Following User Says Thank You to Sean4u For This Useful Post:

    Mr.777 (August 11th, 2011)

  16. #15
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    Thanks Sean4u for sharing such informative links. Did great help....

  17. #16
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Java API to compare two files

    I am not sure where to ask about ocx4j.jar....
    Can i ask here or some other place???
    This is much related to this question that's why i posted here.

  18. #17
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java API to compare two files

    This thread has been cross posted here:

    http://www.java-forums.org/forum-lobby/62441-help-please.html

    Although cross posting is allowed, for everyone's benefit, please read:

    Java Programming Forums Cross Posting Rules

    The Problems With Cross Posting


Similar Threads

  1. Compare instance of a class to another
    By srs in forum Java Theory & Questions
    Replies: 5
    Last Post: December 2nd, 2010, 10:39 AM
  2. Compare method
    By Evelina in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 16th, 2010, 02:07 PM
  3. Trying to somehow Compare Generics
    By Omega_ryan in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 14th, 2010, 12:58 PM
  4. how to compare two set values
    By humdinger in forum Collections and Generics
    Replies: 1
    Last Post: March 13th, 2010, 11:46 AM
  5. String + Compare // Might be too easy for ya
    By Jangan in forum Java Theory & Questions
    Replies: 1
    Last Post: October 18th, 2009, 05:40 PM