0

I am creating folder within a folder from java. Whenever the data loads, the directory should be reloaded with the new data. My code is:

String ResultPath = System.getProperty("user.home") + "\\Desktop\\Report";
new File(ResultPath).mkdir();
new File(ResultPath + "\\images").mkdir();

I have used :

FileUtils.deleteDirectory(new File(ResultPath)); 

in the if else loop to execute the same, but it is not displaying the desired output.

nbro
  • 15,395
  • 32
  • 113
  • 196
Garima Rawat
  • 21
  • 2
  • 5
  • 3
    Possible duplicate of [deleting folder from java](http://stackoverflow.com/questions/3775694/deleting-folder-from-java) – B001ᛦ Mar 21 '17 at 14:30
  • What is the "desired output"? – nbro Mar 21 '17 at 14:31
  • 1
    Possible duplicate of [Delete directories recursively in Java](http://stackoverflow.com/questions/779519/delete-directories-recursively-in-java) – VGR Mar 21 '17 at 14:32
  • @nbro _Whenever the data loads, the directory should be reloaded with the new data_ – B001ᛦ Mar 21 '17 at 14:35
  • 1
    @bub Reloading and deleting are different things. What does "whenever the data loads" actually mean? Which data? – nbro Mar 21 '17 at 14:36
  • @nbro I think she means when she reads from the directory after creating the directory...but you are right, it is not 100% clear. – B001ᛦ Mar 21 '17 at 14:38

1 Answers1

0

I don't get what you actually meant but to delete a directory using Java 8 API :

if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) {
  Files.walk(path)
       .sorted(Comparator.reverseOrder())
       .map(Path::toFile)
       .forEach(File::delete);
}

Do not forget to put the LinkOption.NOFOLLOW_LINKS option to not follow symbolic links as this can be dangerous.

MadJlzz
  • 767
  • 2
  • 13
  • 35