reading files from a directory and comparing the files in a nested for loop in java. first files compare but the rest says "not the same" even though it is same. I know I have to adjust something in my loop to prevent it from sending null values, any pointers
File Directory = new File (location);
File files[] = Directory.listFiles();
for (File f : files)
{
for (File g : files)
{
br = new BufferedReader (new FileReader (f));
while(( z = br.readLine()) != null) s1+= z;
br2 = new BufferedReader (new FileReader (g));
while ((y = br2.readLine()) != null) s2 += y;
System.out.println();
// System.out.println(s1);
// System.out.println(f.getName() + "=" + g.getName());
if (s1.equals(s2)) {
System.out.println(f.getName() + "=" + g.getName());
System.out.println( "Content of both files are same");
}
else {
System.out.println(f.getName() + "!=" + g.getName());
System.out.println("Content of both files are not same");
}
}