Closed Kojoley closed 1 year ago
import java.lang.*; import java.io.File; 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 final class Main { public static void main(String[] args) throws java.io.IOException { try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get("path/to/dir"))) { for (Path entry: stream) { System.out.println(entry.toString()); } } try (DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get("path/to/dir").toAbsolutePath())) { for (Path entry: stream) { System.out.println(entry.toString()); } } } }
C:\w>mkdir path\to\dir\somedir C:\w>echo > path\to\dir\file.txt C:\w>"C:\Program Files\Java\jdk1.8.0_301\bin\javac.exe" Main.java C:\w>"C:\Program Files\Java\jdk1.8.0_301\bin\java.exe" Main path\to\dir\file.txt path\to\dir\somedir C:\w\path\to\dir\file.txt C:\w\path\to\dir\somedir C:\w>C:\ikvm\bin\java.exe Main path\to\dir\path\to\dir\file.txt path\to\dir\path\to\dir\somedir C:\w\path\to\dir\file.txt C:\w\path\to\dir\somedir