Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

file comparison

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

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



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

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 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
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 );
// This is done late, to be same size as # lines in input
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.