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

Google App Engine: store uploaded file in Google Cloud Storage

python google-app-engine webapp2

I have managed to create a file in GCS in the post method of a webapp2 handler of a Google App Engine application. I can't see how to copy the content of a posted file in the file created in GCS.

Easiest way to download HTML page from web?

c++ http wxwidgets

I have a web page whose content I'd like to download into a wxString.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.