FileUtils { public static String getDelta(File parent, File child) { final List<String> _parent = split(parent.getAbsoluteFile()); final List<String> _child = split(child.getAbsoluteFile()); if (!isChild(_parent, _child)) throw new IllegalStateException("Child directory '" + child + "' is not a child of the base directory '" + parent + "'."); StringBuilder path = new StringBuilder(); int index = getNumberOfCommonElements(_parent, _child); for (int size = _child.size(); index < size; index++) { if (path.length() != 0) path.append(File.separator); path.append(_child.get(index)); } return path.toString(); }  static void mkdirs(final File f); static void deleteDirectory(final File directory); static String getDelta(File parent, File child); static String getRelativePath(String targetPath, String basePath, String pathSeparator); static boolean isSymbolicLink(File file); static void createSymbolicLink(final File source, final File target); static boolean isChild(File parent, File child); static String ensureLeadingSlash(final String path); static String getAppendix(final File f);  }
@Test public void testGetDelta() throws Exception { Assert.assertEquals("source/dir", FileUtils.getDelta(new File("/home/abc/def"), new File("/home/abc/def/source/dir"))); }
@Test(expected = IllegalStateException.class) public void testNoCommonPath() throws Exception { FileUtils.getDelta(new File("/home/abc"), new File("/home/def")); }