-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperationOnFile.java
More file actions
79 lines (63 loc) · 2.02 KB
/
OperationOnFile.java
File metadata and controls
79 lines (63 loc) · 2.02 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.io.IOException;
public class OperationOnFile {
public static void CreateMainFolder(String foldName) {
File file = new File(foldName);
if(!file.exists()) {
file.mkdirs();
}
}
public static void CreateFile(String name) {
CreateMainFolder("/Users/essehalagahkomlavi/Desktop/ess");
Path pathOfFolder = Paths.get("/Users/essehalagahkomlavi/Desktop/ess/" + name);
try {
Files.createDirectories(pathOfFolder.getParent());
Files.createFile(pathOfFolder);
System.out.println(name +" file created successfully");
} catch(IOException ex) {
System.out.println("Failed to create the file" + name);
}
}
public static void RetriveInAacendingOrder() {
File file;
File[] paths;
file = new File("/Users/essehalagahkomlavi/Desktop/ess");
paths = file.listFiles();
List<File> listFile = Arrays.asList(paths);
Collections.sort(listFile);
for(File path: paths) {
//print the each file name
System.out.println("|==== " + path.getName());
}
}
public static void DeleteFile(String path) {
CreateMainFolder("/Users/essehalagahkomlavi/Desktop/ess");
Path pathOfFolder = Paths.get("/Users/essehalagahkomlavi/Desktop/ess/" + path);
try {
Files.createDirectories(pathOfFolder.getParent());
Files.delete(pathOfFolder);
System.out.println("File Deleted Successfully!");
}catch (IOException ex) {
System.out.println("File Not Found");
}
}
public static void SearchForFile( String fileName) {
File file = new File("/Users/essehalagahkomlavi/Desktop/ess");
File[] cile = file.listFiles();
boolean found = false;
for(File fill : cile) {
if(fill.getName().startsWith(fileName))
System.out.println("File Found!!!");
found = true;
}
if(found == false)
System.out.println("File Not Found");
}
}