List only files, not subdirectories, and doesn't list hidden files - Java File Path IO

Java examples for File Path IO:Directory Content

Description

List only files, not subdirectories, and doesn't list hidden files

Demo Code

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

public class Main {
  public static void main(String[] arg) throws IOException {
    String path = "c:/test1";
    File dir = new File(path);
    if (dir.isDirectory()) {
      File[] files = dir.listFiles();
      for (File f : files) {
        if (f.isFile() && !f.isHidden())
          System.out.println(f.getName());
      }/*  w w  w.j a v  a2  s  .  c om*/
    }

  }
}

Related Tutorials