question: public static void checkDirectoryIsWriteable ( @ NotNull File directory ) throws IOException { while ( ! directory . exists ( ) || ! directory . isDirectory ( ) ) { directory = directory . getParentFile ( ) ; } if ( ! directory . canWrite ( ) ) { throw new IOException ( "Cannot write to folder: " + directory . getAbsolutePath ( ) ) ; } }
target:  Find the first parent directory that exists and check if this directory is writeable.