public static void ensureDirectoryExists(File dir){
  if (dir != null && (!dir.exists() || !dir.isDirectory())) {
    dir.mkdirs();
  }
}

public static void ensureDirectoryExists ( File dir ) { if ( dir != null && ( ! dir . exists ( ) || ! dir . isDirectory ( ) ) ) { dir . mkdirs ( ) ; } }
check if folder exists . if not - it will be created with with all subdirectories .
