-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile1.java
More file actions
58 lines (47 loc) · 1.47 KB
/
file1.java
File metadata and controls
58 lines (47 loc) · 1.47 KB
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
49
50
51
52
53
54
55
56
57
58
//file information
/*
Name StringX.java
Path C:\Users\ABHIJEET\Desktop\javaa\StringX.java
Access permission
Writable true
Readable true
Isfile true
Isdir false
Data modified Sun Jul 24 13:53:30 PDT 2022
Length 673 bytes
*/
import java.io.File;
import java.lang.*;
import java.util.*;
class file1
{
public static void main(String arg[])
{
File fobj=new File("StringX.java") ; //to create the object of file
//check if file exist
if(fobj.exists())
{
//Name of file
System.out.println("Name "+fobj.getName());
//path of file
System.out.println("Path "+fobj.getAbsolutePath());
//check access permission
System.out.println("Access permission");
System.out.println("Writable "+fobj.canWrite());
System.out.println("Readable "+fobj.canRead());
//check if it is directory or file
System.out.println("Isfile "+fobj.isFile());
System.out.println("Isdir "+fobj.isDirectory());
//last modified date of file or directory
Date d=new Date(fobj.lastModified());
System.out.println("Data modified "+d);
//Length of file
long length=fobj.length();
System.out.println("Length "+length+" bytes");
}
else
{
System.out.println("File not exist");
}
}
}