-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdir.java
More file actions
42 lines (26 loc) · 899 Bytes
/
dir.java
File metadata and controls
42 lines (26 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.io.*;
public class Dir extends Thread {
private File file;
private String name;
public Dir(String name){
this.name = name;
}
public void run(){
file = new File(name);
//Checking whether the file exists
if(file.exists()) {
// listOfFiles array is created to store all the files and folders in the specified path
File[] listOfFiles = file.listFiles();
// Looping is done for printing the array
for(int i=0;i<listOfFiles.length;i++) {
// Print by listing all the files and folders of the given path
System.out.println(listOfFiles[i].getName());
}
//Checking whether the file not exists
if(!file.exists()) {
// throwing error if the directory does not exist
System.out.println("The directory name does not exist");
}
}
}
}