• Post Reply Bookmark Topic Watch Topic
  • New Topic

Comparint contents of 2 files in different folders  RSS feed

 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 3329
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops. Forgot a for() loop in there.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
}
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!