-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileInfo.java
More file actions
30 lines (22 loc) · 1001 Bytes
/
Copy pathFileInfo.java
File metadata and controls
30 lines (22 loc) · 1001 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
package filehandling;
import java.io.File;
public class FileInfo {
public static void main(String[] args) {
File f0 = new File("C:FileOperationExample.txt");
if (f0.exists()) {
// Getting file name
System.out.println("The name of the file is: " + f0.getName());
// Getting path of the file
System.out.println("The absolute path of the file is: " + f0.getAbsolutePath());
// Checking whether the file is writable or not
System.out.println("Is file writeable?: " + f0.canWrite());
// Checking whether the file is readable or not
System.out.println("Is file readable " + f0.canRead());
// Getting the length of the file in bytes
System.out.println("The size of the file in bytes is: " + f0.length());
}
else {
System.out.println("The file does not exist.");
}
}
}