How to get the list of only Files in a directory in java?

here ist an example explain how to list only Files in a directory in java.

package com.nourit.javaIO;

import java.io.File;

public class ListOnlyFilesInDirectory {

  public static void main(String[] args) {
    File folder = new File("D:/tmp");
    File[] files = folder.listFiles();

    for (File file : files) {
      if (file.isFile()) {
        System.out.println(file.getName());
      }
    }
  }
}

Output:

nourit-test-1.txt
nourit-test-2.txt
nourit-test-3.txt
nourit.txt
nourit1.txt
temp-nourit-file-name7880135018657413763.tmp

 

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*