I have this code that tell me if the 2 files have the same content. However, I want to expand this to not just one file but to directory Files. In other words, compare files in one folder to files in another to see if they have same or different contents and if so print it out.
In doing this is it just a matter of modifying the directory paths? My code is below. I think I remember reading somewhere that I may need import another library. Any help would be appreciated.
Problem now I am having is printing out the file name from the area that are the same and that are not the same I tried .getName it is not working my result come back (true) (instead of the names of the files that meet the condition
Code below
import java.io.File;
public class F2FCompare {
public static void main(String[] args)
{
File folderA = new File("C:/Users/hoflerj/Desktop/FolderA");
File[] listOfFilesInA = folderA.listFiles();
File folderB = new File("/C:/Users/hoflerj/Desktop/FolderB");
File[] listOfFilesInB = folderB.listFiles();
for (File fileA : listOfFilesInA){
if (fileA.isFile())
{
for (File fileB : listOfFilesInB) {
if(fileB.isFile())
{
if ( fileA.equals(fileB))
{
System.out.println( "FolderA same as FolderB" + listOfFilesInA.equals(listOfFilesInB) );
//File[] files = folder.listFiles();
}
// txtfile.getName()
else
{
//System.out.println(! fileA.getName().equals(fileB) + " Folder A diff B" );
System.out.println( "Folder same as FolderB " + !fileA.getName().equals(fileB) );
}
}
}
}
}
}
}