aspose file tools*
The moose likes Beginning Java and the fly likes programatic diff tool Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "programatic diff tool" Watch "programatic diff tool" New topic
Author

programatic diff tool

Joe Von
Ranch Hand

Joined: Feb 22, 2001
Posts: 32
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
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
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

Joined: Jul 10, 2001
Posts: 234
Oops! An error in my code:
line = lnr.getLineNumber();
text = lnr.readLine();

should read
lineNumber = lnr.getLineNumber();
lineText = lnr.readLine();
Joe Von
Ranch Hand

Joined: Feb 22, 2001
Posts: 32
Cool.
Thanks BJ.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: programatic diff tool