public static File ensureWriteableDirectory ( File dir ) throws IOException { if ( ! dir . exists ( ) ) { boolean success = dir . mkdirs ( ) ; if ( ! success ) { throw new IOException ( "Failed to create directory: " + dir ) ; } } else { if ( ! dir . canWrite ( ) ) { throw new IOException ( "Dir " + dir . getAbsolutePath ( ) + " not writeable." ) ; } else if ( ! dir . isDirectory ( ) ) { throw new IOException ( "Dir " + dir . getAbsolutePath ( ) + " is not a directory." ) ; } } return dir ; }
Ensure writeable directory .