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());
              }
       }

}

Java Quick Program

1. Write a Code to generate Random numbers public class GenerateRandomNumbers { public static void main(String[] args) { System.out...