public static File ensureDir ( File tgtDir ) throws Exception { if ( tgtDir . exists ( ) ) { if ( tgtDir . isDirectory ( ) ) return tgtDir ; else throw new Exception ( "Could not create directory " + tgtDir . getAbsolutePath ( ) + ", as a file already exists at that path." ) ; } else { tgtDir . mkdirs ( ) ; return tgtDir ; } }
Given a filepath makes sure a directory exists there . If not creates and returns it . Same as ENSURE - DIRECTORY in CL .