public static boolean fileInsideDirectory ( final File dir , final File file ) { checkNotNull ( "dir" , dir ) ; checkNotNull ( "file" , file ) ; final String dirPath = getCanonicalPath ( dir ) ; final String filePath = getCanonicalPath ( file ) ; return filePath . startsWith ( dirPath ) ; }
Checks if a given file is inside the given directory .