public static void makeSecurityCheck ( final File file , final File base ) { if ( ! file . getAbsolutePath ( ) . startsWith ( base . getAbsolutePath ( ) ) ) { throw new IllegalArgumentException ( "Illegal file path [" + file + "]" ) ; } }
Check to make sure the user has not put .. anywhere in the path to allow overwriting of system files . Throws IllegalArgumentException if it fails the check .