Here you can find the source of deleteFileOrDirectory(final File source)
public static void deleteFileOrDirectory(final File source)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; public class Main { public static void deleteFileOrDirectory(final File source) { if (source.isFile()) { Path path = source.toPath(); try { Files.deleteIfExists(path); } catch (IOException | SecurityException e) { System.err.println(e); }//w w w . j av a 2 s.c o m return; } for (String element : source.list()) { deleteFileOrDirectory(new File(source.getPath(), element)); } Path path = source.toPath(); try { Files.deleteIfExists(path); } catch (IOException | SecurityException e) { System.err.println(e); } } }