Java:无法使用FileUtils.deleteQuietly删除文件,ForceDelete,FileDeleteStrategy.FORCE.delete;

时间:2016-06-07 10:55:25

标签: java file apache-commons

我使用FileUtils.deleteQuietly()方法在复制到其他一些地方后删除文件。但它没有删除文件,文件也停留在同一条路径中。

    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....");
    }

1 个答案:

答案 0 :(得分:1)

  • 由于文件权限问题而发生这种情况。
  • 获得许可后,工作正常,上述代码没有问题。