@Test public void testCleanDirectory() throws Exception { for (int i = 0; i < 10; i++) { IOTinyUtils.writeStringToFile(new File(testRootDir, "testCleanDirectory" + i), "testCleanDirectory", RemotingHelper.DEFAULT_CHARSET); } File dir = new File(testRootDir); assertTrue(dir.exists() && dir.isDirectory()); assertTrue(dir.listFiles().length > 0); IOTinyUtils.cleanDirectory(new File(testRootDir)); assertTrue(dir.listFiles().length == 0); }
public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { delete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } }
IOTinyUtils { public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { delete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } } }
IOTinyUtils { public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { delete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } }  }
IOTinyUtils { public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { delete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } }  static String toString(InputStream input, String encoding); static String toString(Reader reader); static long copy(Reader input, Writer output); static List<String> readLines(Reader input); static void copyFile(String source, String target); static void delete(File fileOrDir); static void cleanDirectory(File directory); static void writeStringToFile(File file, String data, String encoding); }
IOTinyUtils { public static void cleanDirectory(File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } File[] files = directory.listFiles(); if (files == null) { throw new IOException("Failed to list contents of " + directory); } IOException exception = null; for (File file : files) { try { delete(file); } catch (IOException ioe) { exception = ioe; } } if (null != exception) { throw exception; } }  static String toString(InputStream input, String encoding); static String toString(Reader reader); static long copy(Reader input, Writer output); static List<String> readLines(Reader input); static void copyFile(String source, String target); static void delete(File fileOrDir); static void cleanDirectory(File directory); static void writeStringToFile(File file, String data, String encoding);  }