Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

file comparison

  Asked By: Harley    Date: Jul 29    Category: Java    Views: 733
  

What would be the best way to compare two files on the
Unix file system, from a Java program?

Share: 

 

2 Answers Found

 
Answer #1    Answered By: Evelyn Hughes     Answered On: Jul 29

Comparison of files  withe respect to what? Do u mean
size, file  content, last accessed date, last modified
time...etc.

and one other small observation since java  is platform
independent and Files are abstracted and represented
by the java.io.File class what ever you do on a
Windows m/c will be applicable with respect to a unix
machine too....

 
Answer #2    Answered By: Douglas Sullivan     Answered On: Jul 29

// Diff -- text file  difference utility.
// See full docu-comment at beginning of Diff class.

// $Id: Diff.java,v 1.1.1.1 1998/10/29 04:25:38 ian Exp $

import java.io.*;

/** This is the info kept per-file. */
class fileInfo {

static final int MAXLINECOUNT = 20000;

DataInputStream file; /* File handle that is open for
read. */
public int maxLine; /* After input done, # lines in
file. */
node symbol[]; /* The symtab handle of each line. */
int other[]; /* Map of line# to line# in other file */
/* ( -1 means don't-
know ). */
/* Allocated AFTER the lines are
read. */

/**
* Normal constructor with one filename; file is opened and
saved.
*/
fileInfo( String filename ) {
symbol = new node [ MAXLINECOUNT+2 ];
other = null; // allocated later!
try {
file = new DataInputStream(
new FileInputStream( filename));
} catch (IOException e) {
System.err.println("Diff can't read file " +
filename );
System.err.println("Error Exception was:" +
e );
System.exit(1);
}
}
// This is done late, to be same size as # lines in input
file.
void alloc() {
other = new int[symbol.length + 2];
}
};

 
Didn't find what you were looking for? Find more on file comparison Or get search suggestion and latest updates.




Tagged: