-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileExample.java
More file actions
39 lines (30 loc) · 976 Bytes
/
FileExample.java
File metadata and controls
39 lines (30 loc) · 976 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
package io;
import java.io.File;
public class FileExample {
public static void main(String[] args) {
/* Instantiate File */
File file = new File("D:\\ab.txt");
// Check if above path is Directory?
boolean isDirectory = file.isDirectory();
System.out.println("ab.txt is directory: " + isDirectory);
/* File exist of not */
boolean isFileExits = file.exists();
System.out.println("File is exist: " + isFileExits);
/* Create Directory */
File fDir = new File("D:\\JavaStud");
boolean dirCreated = fDir.mkdir();
if (dirCreated) {
System.out.println("JavaStud is successfully created.");
}
/* List name of all files */
String[] fileNames = fDir.list();
for (String fileName : fileNames) {
System.out.println(fileName);
}
/* List of Files */
File[] files = fDir.listFiles();
for (File file2 : files) {
System.out.println(file2.getAbsolutePath() + " " + file2.isDirectory());
}
}
}