Ilavarasan Jayaraman
Ilavarasan Jayaraman

Reputation: 303

Java : Unable to delete files using FileUtils.deleteQuietly,ForceDelete,FileDeleteStrategy.FORCE.delete;

I use FileUtils.deleteQuietly() method to delete files after copying to some other places.But it is not deleting the file and the files are staying in the same path.

    File folder = new File(Marker_Source_path);
    File[] listOfFiles = folder.listFiles();
    if(folder.exists() && folder.isDirectory() && folder.list().length>0)
    {
        for (int i = 0;i<listOfFiles.length; i++) 
        {       
            if (listOfFiles[i].isFile()) 
            {
                String Filename= listOfFiles[i].getName();
                String Filename_path=listOfFiles[i].getAbsolutePath();
                File File_with_path=new File(Filename_path);
                FileUtils.copyFileToDirectory(File_with_path, destinationDir2_TITLE_MM);
                FileUtils.copyFileToDirectory(File_with_path, destinationDir3_PUB_TYPE);
                FileUtils.copyFileToDirectory(File_with_path, destinationDir4_ISSUE_FREQ);
                FileUtils.copyFileToDirectory(File_with_path, destinationDir4_VOL_ISSUE);
 System.out.println("Marker File : " + Filename + " Moved to destination Dir : "+ destinationDir2_TITLE_MM.getAbsolutePath() + " 
           Successfully...");
         Boolean check_del=FileUtils.deleteQuietly(File_with_path);
              System.out.println("Is File deleted : "+check_del);
            }
        }     
    }
    else
    {
        System.out.println("No Markers to Copy....");
    }

Upvotes: 0

Views: 11603

Answers (1)

Ilavarasan Jayaraman
Ilavarasan Jayaraman

Reputation: 303

  • This is Happened due to the File permission issue.
  • After Giving permission it works fine and no issue with the above code.

Upvotes: 1

Related Questions