Does Files.createTempDirectory remove the directory after JVM exits normally?

前端 未结 5 806
滥情空心
滥情空心 2020-12-15 04:06

Does Files.createTempDirectory remove the directory after JVM exits normally? Or do I need to manually recursively remove the temporary directory content?

5条回答
  •  [愿得一人]
    2020-12-15 04:48

    You can add apache commons io dependency to your project and then use FileUtils.deleteDirectory() to do something like:

    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
            try {
                FileUtils.deleteDirectory(tmp_dir_path.toFile());
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
    });
    

    For more information about apache commons check: https://commons.apache.org/proper/commons-io/

提交回复
热议问题