list Files And Files Sub Directories - Java File Path IO

Java examples for File Path IO:Directory Content

Description

list Files And Files Sub Directories

Demo Code


import java.io.File;
import java.io.IOException;

public class Main{
  public static void main(String[] args) throws NumberFormatException, IOException {
    long st = Long.parseLong(args[0]);
    long end = Long.parseLong(args[1]);
    String directoryLinux = "/Users/yourName/test";
    listFilesAndFilesSubDirectories(directoryLinux, st, end);
  }/*  w w  w  .j a  va 2 s. com*/
  public static void listFilesAndFilesSubDirectories(String directoryName, long st, long end) {
    File directory = new File(directoryName);
    File[] flist = directory.listFiles();
    for (File file : flist) {
      if (file.isFile()) {
        if (file.lastModified() > st && file.lastModified() < end)
         System.out.println(file.getAbsolutePath());
      } else if (file.isDirectory()) {
        listFilesAndFilesSubDirectories(file.getAbsolutePath(), st, end);
      }
    }
  }
}

Related Tutorials