Path { public static File toRelativeFile(final File srcMountPoint, final File file) throws IOException, IllegalArgumentException { if (file==null || srcMountPoint==null){ throw new IllegalArgumentException("Some passed file argument are null: mountPoint:"+srcMountPoint+" file: "+file); } else if (!file.isAbsolute() || !srcMountPoint.isAbsolute()){ throw new IllegalArgumentException("Some passed file arguments are not absolute: mountPoint:"+srcMountPoint+" file: "+file); } final StringBuffer buf = new StringBuffer(file.getCanonicalPath()); String srcMountPointFilePath = srcMountPoint.getCanonicalPath(); srcMountPointFilePath += File.separator; final int index = buf.indexOf(srcMountPointFilePath); if (index != 0) { throw new IllegalArgumentException("The passed file: \'" + file + "\' is not a child of the source mount point: \'" + srcMountPoint + "\'"); } else { buf.delete(0, srcMountPointFilePath.length()); } return new File(buf.toString()); }  static File findLocation(String location, File directory); static File findLocation(File location, File directory); static String findLocation(String location, String directory); static File createFile(String location, File directory); static File createDirectory(String location, File directory); static File rebaseFile(final File srcMountPoint, final File destMountPoint, final File file); static File toRelativeFile(final File srcMountPoint, final File file); final static File createTodayDirectory(File destDir, String inputFileName, final boolean withTime); final static File createTodayDirectory(File destDir, String inputFileName);  }
@Test public void toRelativeFileTest() throws IllegalArgumentException, IOException{ File rebased=Path.toRelativeFile(srcMountPnt, pathTest); Assert.assertTrue(!rebased.isAbsolute()); Assert.assertTrue(rebased.getPath().equals("inner"+File.separator+"PathTest.txt")); }