We help IT Professionals succeed at work.

comment

motolanix1
motolanix1 asked
on
292 Views
Last Modified: 2013-12-14
This message is for CEHJ. Could you comment the code please? Many thanks for all your support.
File f1 = new File("C:\\Java\\file1SAP.txt");
        File f2 = new File("C:\\Java\\file1FISP.txt");
        System.out.println(filesMatch(f1,f2)? "Well done! - files match" : "Files don't match sorry");
 
    }
 
    public static boolean filesMatch(File f1, File f2) {
       
        boolean result = true;
 
        if (f1.length() != f2.length()) {
            result = false;
            
        } else {
            try {
                FileInputStream in1 = new FileInputStream(f1);
                FileInputStream in2 = new FileInputStream(f2);
 
                int buf = -1;
 
                while (((buf = in1.read()) > -1) && (result == true)) {
                    result = (buf == in2.read());
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
  
        return result;

Open in new window

Comment
Watch Question

You are not closing InputStreams
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.