aspose file tools
The moose likes Java in General and the fly likes Comparint contents of 2 files in different folders Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Comparint contents of 2 files in different folders" Watch "Comparint contents of 2 files in different folders" New topic
Author

Comparint contents of 2 files in different folders

Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 97
I am working on an app that download files from an sftp server...comparing things in a server and on a local machine got a bit too much for me! So i have decided to download the txt. files to a temp folder. What i am trying to do is compare the data newly downloaded txt file with the one in the local machine. So that if the contents of the files are the same i can do X if not Y. Any help! Ive tried hashCode() from java.io.File and lastModified() but those function calls refer to pathfilename and that is why i don't think the comparison is working for me.
Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 159

Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 159

Oops. Forgot a for() loop in there.
Eduardo Ponce de Leon
Ranch Hand

Joined: May 13, 2009
Posts: 97
for some reason that didnt work for me... so i came up with a different approach but i am stuck comparing..
This is where i am getting my error...Is there another way of comparing array of type long

int value = sizeTempFolder[i].compareTo(sizeWorkFolder[i]);


i store

this is in main()
String tempFolder = "C:\\SnapshotClient\\temp"; //temp folder for downloading files
String workFolder = "C:\\SnapshotClient\\DataFiles"; //Work folder for processing Snapshot files

File tempFile = new File(tempFolder); //For working in temp folder
File workFile = new File(workFolder); //For working in work folder

File[] filesInTempFolder = tempFile.listFiles(); //Storing files in temp Folder
File[] filesInWorkFolder = workFile.listFiles();


THIS IS MY FUNCTION CALL---
public static void compareSizeOfFiles(File[] tempFolder, File[] localFolder) {

long sizeTempFolder[] = null;
long sizeWorkFolder[] = null;

System.out.println("*** LISTING CONTENTS OF temp FOLDER ****");
for(int i = 0; i < tempFolder.length; i++){
sizeTempFolder[i] = tempFolder[i].length(); // store size of file in array
System.out.println("Lenght of "+tempFolder[i]+" is "+sizeTempFolder[i]);
}

System.out.println();
System.out.println("*** LISTING CONTENTS OF SnapshotFiles FOLDER ****");
for(int i = 0; i < localFolder.length; i++){
sizeWorkFolder[i] = localFolder[i].length(); // store size of file in array
System.out.println("Lenght of "+localFolder[i]+" is "+sizeWorkFolder[i]);
}

System.out.println("*** COMPARING FILES ****");
for(int i=0; i<tempFolder.length; i++) {
int value = sizeTempFolder[i].compareTo(sizeWorkFolder[i]);
System.out.println(value);
}
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Comparint contents of 2 files in different folders
 
Similar Threads
Uploading File??
File Download/Upload to remote server Path problem
Comparing data in 2 files in different folders
Help needed to compare timestamp
Download multiple files