• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Compare text files

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Im trying to compare two text files in java, I wanted the source file and target file to be displayed side by side and the line which is different needs to be highlighted

I tried with this code, But it only shows the difference, what will I need to change to display two files side by side Like in http://www.comparemyfiles.com/



 
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to do it like the link you'll need a GUI.
If you want to keep it as CLI, print out the files side by side with some marker to show lines that don't match then add a print statement to the if statement that compares the lines for equality. You will need to change the chars you insert between the two concatenated lines so you can see which lines are not the same.
 
Marshal
Posts: 79941
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to minimize your work, use Runtime.exec to run "diff" on the two files and do something with its output (You'd need Unix/Linux underneath, or UnxUtils installed on Windows, though.)

Or check out http://jlibdiff.sourceforge.net/ and http://code.google.com/p/google-diff-match-patch/
 
Campbell Ritchie
Marshal
Posts: 79941
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don’t use StringTokenizer (← click here and it tells you why).
Don’t use a 10000 element array. The alternatives to tokenizer can produce an array of the right size.
 
This is my favorite show. And this is my favorite tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic