Java Stream How to - List file under a folder then sort








Question

We would like to know how to list file under a folder then sort.

Answer

/*from  w  ww. j av  a 2 s.  co m*/
import java.nio.file.Files;
import java.nio.file.Paths;

public class Main {

  public static void main(String[] args) throws Exception{
    Files
    .list(Paths.get("c:/Java_Dev"))
    .sorted()
    .forEach(System.out::println);
  }
}

The code above generates the following result.