@Test public void testMoveDirectory3() throws IOException { final File srcDir = buildOrnidroidHomeTest(TEST_DIRECTORY + "/srcDir"); final File destDir = buildOrnidroidHomeTest(TEST_DIRECTORY + "/destDir"); final File[] srcDirContent = srcDir.listFiles(); try { FileHelper.moveDirectory(srcDir, destDir); final File[] destDirContent = destDir.listFiles(); Assert.assertTrue(srcDirContent.length == destDirContent.length); Assert.assertFalse(srcDir.exists()); } catch (final IOException e) { Assert.fail("no exception should occur"); e.printStackTrace(); } }
public static void moveDirectory(final File srcDir, final File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } boolean rename = false; if (!destDir.exists()) { rename = srcDir.renameTo(destDir); } if (!rename) { if (destDir.getCanonicalPath() .startsWith(srcDir.getCanonicalPath())) { throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } }
FileHelper { public static void moveDirectory(final File srcDir, final File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } boolean rename = false; if (!destDir.exists()) { rename = srcDir.renameTo(destDir); } if (!rename) { if (destDir.getCanonicalPath() .startsWith(srcDir.getCanonicalPath())) { throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } } }
FileHelper { public static void moveDirectory(final File srcDir, final File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } boolean rename = false; if (!destDir.exists()) { rename = srcDir.renameTo(destDir); } if (!rename) { if (destDir.getCanonicalPath() .startsWith(srcDir.getCanonicalPath())) { throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } } private  FileHelper(); }
FileHelper { public static void moveDirectory(final File srcDir, final File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } boolean rename = false; if (!destDir.exists()) { rename = srcDir.renameTo(destDir); } if (!rename) { if (destDir.getCanonicalPath() .startsWith(srcDir.getCanonicalPath())) { throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } } private  FileHelper(); static void createEmptyFile(final File file); static int folderSize(File directory, boolean recursive); static void doCopyFile(final File srcFile, final File destFile); static void forceDelete(final File file); static void forceMkdir(final File directory); static void moveDirectory(final File srcDir, final File destDir); static String[] parseContentFile(final File contentFile); static void writeStringToFile(final File file, final String data,
			final Charset encoding, final boolean append); static boolean unzipFile(String zipname, String destDir); static int getFileSizeInMb(File downloadedFile); static int getCountFiles(File fileToCheck); }
FileHelper { public static void moveDirectory(final File srcDir, final File destDir) throws IOException { if (srcDir == null) { throw new NullPointerException("Source must not be null"); } if (destDir == null) { throw new NullPointerException("Destination must not be null"); } if (!srcDir.exists()) { throw new FileNotFoundException("Source '" + srcDir + "' does not exist"); } if (!srcDir.isDirectory()) { throw new IOException("Source '" + srcDir + "' is not a directory"); } boolean rename = false; if (!destDir.exists()) { rename = srcDir.renameTo(destDir); } if (!rename) { if (destDir.getCanonicalPath() .startsWith(srcDir.getCanonicalPath())) { throw new IOException("Cannot move directory: " + srcDir + " to a subdirectory of itself: " + destDir); } copyDirectory(srcDir, destDir); deleteDirectory(srcDir); if (srcDir.exists()) { throw new IOException("Failed to delete original directory '" + srcDir + "' after copy to '" + destDir + "'"); } } } private  FileHelper(); static void createEmptyFile(final File file); static int folderSize(File directory, boolean recursive); static void doCopyFile(final File srcFile, final File destFile); static void forceDelete(final File file); static void forceMkdir(final File directory); static void moveDirectory(final File srcDir, final File destDir); static String[] parseContentFile(final File contentFile); static void writeStringToFile(final File file, final String data,
			final Charset encoding, final boolean append); static boolean unzipFile(String zipname, String destDir); static int getFileSizeInMb(File downloadedFile); static int getCountFiles(File fileToCheck); static final long ONE_KB; static final long ONE_MB; }