Skip to content

Commit 02f63e5

Browse files
Merge pull request #1 from anshumanjadiya1102/hacktoberfest
Create LsCommand.java
2 parents f7e9090 + 11648ef commit 02f63e5

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import java.nio.file.*;
2+
import java.io.IOException;
3+
4+
public class ListFilesNIO {
5+
public static void main(String[] args) throws IOException {
6+
Path dir = Paths.get("."); // Current directory
7+
8+
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
9+
for (Path path : stream) {
10+
System.out.println(Files.isDirectory(path) ? "[DIR] " + path.getFileName() : " " + path.getFileName());
11+
}
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)