• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

programatic diff tool

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm writing a tool which (among other things) needs to determine if two text files are different and, if different, which line has changed.
Does anyone know of a tool or an API which I can code to which has this sort of functionality?
Thanks,
Joe
 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just use the io package. Do something like this to read your files:
File f = new File("c:\\file.txt");
FileReader fr = new FileReader(f);
LineNumberReader lnr = new LineNumberReader(fr);
String lineText = "";
int lineNumber = 0;
while(text != null)
{
line = lnr.getLineNumber();
text = lnr.readLine();
}
This bit of code should read a file and grab each line, putting it into a String. Just do this to the two files you are interested in, and do a .equals between each line you read in.
Hope this helps.
 
BJ Grau
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops! An error in my code:
line = lnr.getLineNumber();
text = lnr.readLine();

should read
lineNumber = lnr.getLineNumber();
lineText = lnr.readLine();
 
Joe Von
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool.
Thanks BJ.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic