Delete files from md5 list in HashSet

I want to delete file located in local machine, comparing to server machine.

My example :

import java.io.*;

public static void main(String[] args) throws Exception {


        Set<String > lmd5 = new HashSet<String>();
            lmd5.add("4be1babb2f8cac64d96f8052c0942130");
            lmd5.add("a7514d56f233a434c7066176933d708d");
            lmd5.add("d41d8cd98f00b204e9800998ecf8427e");
            lmd5.add("674e3b94be9ed5db8bafe75808385de1");
        Set<String > dmd5 = new HashSet<String>();
            dmd5.add("4be1babb2f8cac64d96f8052c0942130");
            dmd5.add("a7514d56f233a434c7066176933d708d");
            dmd5.add("d41d8cd98f00b204e9800998ecf8427e");

        if(lmd5.equals(dmd5)){
            System.out.println("OK");
        }
        else{
            lmd5.removeAll(dmd5);

            System.out.println("Obsoletes Files To Delete : " + lmd5);

            File[] paths = baseModDirectoryFile.listFiles();
            for(File path:paths){
                FileInputStream fis = new FileInputStream(path);
            String md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
                if(lmd5.contains(md5) ){
                    File foundFile = path;
                    System.out.println("Obsolete File Found !");
                    try{
                        if(foundFile.delete()){
                            System.out.println("Obsolete File Deleted !");
                        }
                        else{
                            System.out.println("Obsolete File Not Deleted : Error !");
                        }
                    }catch(Exception e){
                        e.printStackTrace();
                    }
                }
                else{
                    continue;
                }
            }
        }

}

In my output console, I have the message "Obsoletes Files Found" which appears, but after that I have the message : "Obsolete File Not Deleted". I believe I arrive too late in the function to delete the file, as all files have already been checked.

Maybe I have to review this position but I would like to get some advise.

Thank you !

Answers


What is the value of foundFile.delete()?

Do you have enough permission to delete file?

May be your file is being locked by your FileInputStream?


Need Your Help

How to show the loading indicator in the top status bar

ios cocoa-touch

I have noticed that some apps like Safari and Mail show a loading indicator in the status bar (the bar at the very top of the phone) when they are accessing the network. Is there a way to do the same

The pains of creating a global application

web-applications internationalization global localization globalization

I need to create a global application. This means it should work ok anywhere in the world, at any country (or most of them). It's a PHP website that will deal with money and time at certain points....