• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparint contents of 2 files in different folders

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Carey Brown
Saloon Keeper
Posts: 10732
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oops. Forgot a for() loop in there.
 
Eduardo Ponce de Leon
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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);
}
reply
    Bookmark Topic Watch Topic
  • New Topic