Results 1 to 4 of 4
  1. #1
    DynamicTrubo is offline Member
    Join Date
    Jan 2014
    Location
    Berlin, Germany
    Posts
    2
    Rep Power
    0

    Default How to write a diff, comparing two .txt files.

    Hello, im new totally new to java and pretty new to programming as well.
    I have to write a diff which will compare two txt files, diff have to return changes and additional lines in console with indicating in what file and line.
    Example:

    File1:
    This is war
    on the front.
    Flying is cool.

    File2:
    This is war
    on the beach.
    Something here.
    Flying is cool.

    Result of this should be:
    Changed lines:
    line2/line2 - on the front./beach.
    file1 line2 on the front.
    file2 line2 on the beach.
    Additional lines:
    file2 line3 Something here.

    Hopefully someone will be able to help me with this.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to write a diff, comparing two .txt files.

    An excellent question for Google; I typed in "diff algorithm" and among other stuff, it found this: diff - Wikipedia, the free encyclopedia

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    DynamicTrubo is offline Member
    Join Date
    Jan 2014
    Location
    Berlin, Germany
    Posts
    2
    Rep Power
    0

    Default Re: How to write a diff, comparing two .txt files.

    Quote Originally Posted by JosAH View Post
    An excellent question for Google; I typed in "diff algorithm" and among other stuff, it found this: diff - Wikipedia, the free encyclopedia

    kind regards,

    Jos
    Oh, could you brighten it to me alot more, like what loops i should use etc. Anyways ty :)

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,762
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to write a diff, comparing two .txt files.

    You should've googled a bit more; this is a page full of references: Diff Algorithm

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 10
    Last Post: 02-06-2013, 07:12 PM
  2. Comparing 2 CSV files
    By gcclinux in forum New To Java
    Replies: 6
    Last Post: 04-13-2011, 11:37 AM
  3. comparing the two files
    By trkece in forum New To Java
    Replies: 0
    Last Post: 02-21-2011, 11:27 AM
  4. Comparing two XML files
    By anuj_sharma in forum XML
    Replies: 1
    Last Post: 02-07-2011, 10:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •