-
Notifications
You must be signed in to change notification settings - Fork 0
/
Contents.java
48 lines (45 loc) · 974 Bytes
/
Contents.java
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
43
44
45
46
47
48
// Program to show the content of a directory;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
class Contents
{
public static void main(String args[])
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter Directory name");
String fname = scan.nextLine();
File f = new File(fname);
if(f.exists())
{
if(f.isFile())
{
System.out.println("Not a Directory");
}
else
{
String[] arr = f.list();
int len = arr.length;
for(int i=0;i<len;i++)
{
System.out.println(i+ ". Name : "+arr[i]);
File f1 = new File(fname,arr[i]);
if(f1.isFile())
{
System.out.println("Type : File" );
}
else if(f1.isDirectory()){
System.out.println("Type : Directory" );
}
else{}
}
}
}
else
{
System.out.println("No such Directory");
}
}
}