-2

I want to compare two txt files line by line. I also want to show the differences with colored lines. Finally, I want to bold the letters or words that are different on each line.

Is this possible? Can you give me an idea to start somewhere?

irrelephant
  • 4,091
  • 2
  • 25
  • 41
Jes
  • 21
  • 8
  • I'd recommend learning swing: http://docs.oracle.com/javase/tutorial/uiswing/ – bcr Aug 01 '12 at 06:53
  • There appears to be a very similar question here: http://stackoverflow.com/questions/2019089/java-gui-component-for-displaying-diffs – Wouter Lievens Aug 01 '12 at 06:55
  • I have created try1.txt and try2.txt I wrote some sentences in it. I want to compare two files line by line. I think diff algorithm helps me but it was so confunsing to me. – Jes Aug 01 '12 at 06:57

2 Answers2

4

we are using http://jlibdiff.sourceforge.net for file diff indentifications, maybe it can help you as well

<dependency>
   <groupId>jlibdiff</groupId>
   <artifactId>jlibdiff</artifactId>
   <version>1.01</version>
</dependency>
Andrey Borisov
  • 3,160
  • 18
  • 18
1

You needed a start, well here is one:

  1. Build the core, that compares the text files. Use a structure (ie: class) that represents one line with differences. It should hold the old and new line (to start with).
  2. Test the core with some test files in the command line, until it works.
  3. Now, you know that it works, you can build the GUI in Swing. You will need a JFrame and two JTextPane, which is made uneditable. Use Google to find out how to do the text formatting in a JTextPane.
Martijn Courteaux
  • 67,591
  • 47
  • 198
  • 287