private void checkDirectory(){
  if (!directory.exists()) {
    boolean created=directory.mkdirs();
    if (!created) {
      throw new RuntimeException(String.format("Unable to create the path '%s'.",directory));
    }
  }
 else   if (!directory.canWrite()) {
    throw new RuntimeException(String.format("The path '%s' is not writable.",directory));
  }
}

private void checkDirectory ( ) { if ( ! directory . exists ( ) ) { boolean created = directory . mkdirs ( ) ; if ( ! created ) { throw new RuntimeException ( String . format ( "Unable to create the path '%s'." , directory ) ) ; } } else if ( ! directory . canWrite ( ) ) { throw new RuntimeException ( String . format ( "The path '%s' is not writable." , directory ) ) ; } }
checks that the directory provided either exists and is writable or doesn ' t exist but can be created .
