I've searched and found suggestions, but hit a wall with comparing a List of Files from one directory to another. I want to print the files in the second directory that are also contained in the first. Here's what I have so far:
import java.io.File;
public class diffcheck2
{
public static void main(String[] args)
{
//populate the arrays
File f = new File("C:/DIFFCHECK/DIR1/");
File[] rec = f.listFiles();
File g = new File("C:/DIFFCHECK/DIR2/");
File[] hist = g.listFiles();
//loop through the contents of rec
//and comparing each element to each element in hist
//boolean foundSwitch = false;
//outer loop for all the elements in rec[i]
for(int i = 0; i < rec.length; i++)
{
//inner loop for all the elements in hist[j]
for (int j = 0; j < hist.length;j++)
{
//compare rec to hist and output results
if( rec[i].equals(hist[j]))
{
//foundSwitch = true;
System.out.println( "Received File" + rec[i] + " was found in Trans Hist" );
}
else {
System.out.println("no dups");
}
}
}
}
}
C:/DIFFCHECK/DIR1/ contains: TEST_DUP.txt, TEST_UNI.txt
C:/DIFFCHECK/DIR2/ contains: TEST2.txt, TEST_DUP.txt
I'm looking for it to print: TEST_DUP.txt
Here's the output I receive:
no dups
no dups
no dups
no dups
I'm not sure what I'm doing wrong.

New Topic/Question
Reply



MultiQuote







|