Sunday, March 31, 2013

How to find files in a directory using DirectoryStream



package com.swain.cell;

import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FindFilesInDirectory {
       public static void main(String[] args) {
              Path dir = Paths.get("c:\\JAVA");

              try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,
                           "*.*")) {
                     for (Path entry : stream) {
                           System.out.println(entry.getFileName());
                     }
              } catch (IOException e) {
                     System.out.println(e.getMessage());
              }
       }

}

No comments:

Post a Comment

How ChatGPT can Benefit Coding: Your Guide to Leveraging an AI Language Model

 Introduction: Hello, coders! Welcome to this blog post on how ChatGPT, an AI language model, can benefit your coding skills and projects. A...