FileManager { public static void cleanDirectory(@NonNull File directory) { File[] contents = directory.listFiles(); if (contents != null) { for (File file : contents) { deleteDirectory(file); } } }  static synchronized void initialize(Context context); @SuppressWarnings("SameParameterValue") static String read(@NonNull String path); static String read(@NonNull File file); static byte[] readBytes(@NonNull File file); static void write(@NonNull String path, @NonNull String contents); static void write(@NonNull File file, @NonNull String contents); @SuppressWarnings("WeakerAccess") @NonNull static String[] getFilenames(@NonNull String path, @Nullable FilenameFilter filter); @SuppressWarnings("WeakerAccess") @Nullable static File lastModifiedFile(@NonNull String path, @Nullable FilenameFilter filter); @Nullable static File lastModifiedFile(@NonNull File dir, @Nullable FilenameFilter filter); static boolean delete(@NonNull String path); static boolean delete(@NonNull File file); static boolean deleteDirectory(@NonNull File file); static void cleanDirectory(@NonNull File directory); @SuppressWarnings("ResultOfMethodCallIgnored") static void mkdir(@NonNull String path);  }
@Test public void cleanDirectory() throws IOException { File folder = mTemporaryFolder.newFolder(); File file1 = new File(folder, "file1"); assertTrue(file1.createNewFile()); assertTrue(file1.exists()); File file2 = new File(folder, "file2"); assertTrue(file2.createNewFile()); assertTrue(file2.exists()); FileManager.cleanDirectory(folder); assertFalse(file2.exists()); assertFalse(file1.exists()); assertTrue(folder.exists()); }
@Test public void cleanDirectoryWhenNotDirectory() throws IOException { File folder = mTemporaryFolder.newFolder(); File file1 = new File(folder, "file1"); assertTrue(file1.createNewFile()); assertTrue(file1.exists()); FileManager.cleanDirectory(file1); }