Files2 { @Nullable public static File getRelativeFile(@NonNull File[] paths, @NonNull File file) { if (!file.isAbsolute()) { return file; } String path = file.getAbsolutePath(); for (File parent : paths) { String parentPath = parent.getAbsolutePath() + File.separator; if (path.startsWith(parentPath)) { return new File(path.substring(parentPath.length())); } } return null; } private  Files2(); static File fromPath(String parent, String... path); @Deprecated static boolean isValidPath(File file); @Nullable static File getAbsoluteFile(@NonNull File[] paths, @NonNull File file); @Nullable static File getRelativeFile(@NonNull File[] paths, @NonNull File file); static boolean acceptByLowerCaseExtension(File pathname, String... lowerCaseExtensions); @Nullable static File extractFile(@NonNull String path);  }
@Test public void testGetRelativeFile() { assertEquals(RELATIVE_INSIDE, Files2.getRelativeFile(PATHS, RELATIVE_INSIDE)); assertSame(RELATIVE_INSIDE, Files2.getRelativeFile(PATHS, RELATIVE_INSIDE)); assertFalse(Files2.getRelativeFile(PATHS, RELATIVE_INSIDE).isAbsolute()); assertEquals(RELATIVE_INSIDE, Files2.getRelativeFile(PATHS, ABSOLUTE_INSIDE)); assertNotSame(RELATIVE_INSIDE, Files2.getRelativeFile(PATHS, ABSOLUTE_INSIDE)); assertFalse(Files2.getRelativeFile(PATHS, ABSOLUTE_INSIDE).isAbsolute()); assertEquals(RELATIVE_OUTSIDE, Files2.getRelativeFile(PATHS, RELATIVE_OUTSIDE)); assertSame(RELATIVE_OUTSIDE, Files2.getRelativeFile(PATHS, RELATIVE_OUTSIDE)); assertFalse(Files2.getRelativeFile(PATHS, RELATIVE_OUTSIDE).isAbsolute()); assertNotEquals(RELATIVE_OUTSIDE, Files2.getRelativeFile(PATHS, ABSOLUTE_OUTSIDE)); assertNotSame(RELATIVE_OUTSIDE, Files2.getRelativeFile(PATHS, ABSOLUTE_OUTSIDE)); assertNull(Files2.getRelativeFile(PATHS, ABSOLUTE_OUTSIDE)); }