-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInfo.java
More file actions
29 lines (22 loc) · 864 Bytes
/
FileInfo.java
File metadata and controls
29 lines (22 loc) · 864 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
import java.util.Scanner;
import java.io.File;
public class FileInfo {
public static void main(String[] args) {
try(Scanner scan = new Scanner(System.in)){
System.out.println("Enter the file name");
String fileName = scan.nextLine();
File file = new File(fileName);
if(file.exists()){
System.out.println("File Exists: yes");
System.out.println("File Can Read: " + file.canRead());
System.out.println("File can Write: " + file.canWrite());
System.out.println("File Type: " + (file.isDirectory() ? "Directory" : "File"));
System.out.println("File Size: " + file.length() + " bytes");
}
else{System.out.println("File Exists: No");}
}
catch(Exception e){
System.out.println("Error: " + e.getMessage());
}
}
}