list Files and returns a sorted set - Android java.io

Android examples for java.io:Directory

Description

list Files and returns a sorted set

Demo Code

import java.io.File;
import java.util.Arrays;
import java.util.SortedSet;
import java.util.TreeSet;

import android.util.Log;

public class Main {

  private static final String TAG = "";

  /**//  ww  w .j a va  2s .c o m
   * Similar to {@link java.io.File#listFiles()}, but returns a sorted set. Never
   * returns {@code null}, instead a warning is logged, and an empty set is
   * returned.
   */
  public static SortedSet<File> listFiles(File dir) {
    File[] files = dir.listFiles();
    if (files == null) {
      Log.w(TAG, "Failed to list children for " + dir.getPath());
      return new TreeSet<File>();
    }

    return new TreeSet<File>(Arrays.asList(files));
  }

}

Related Tutorials