-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLockedMe.java
More file actions
182 lines (159 loc) · 3.94 KB
/
LockedMe.java
File metadata and controls
182 lines (159 loc) · 3.94 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package SimplilearnFinalProject;
import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.Scanner;
public class LockedMe {
static final String projectFilesPath="C:\\Users\\Ravi\\Desktop\\LockedMe Project";
/**
* this method will display menu
*/
public static void displayMenu()
{
System.out.println("***********************************");
System.out.println("\tWelcome to LockedMe.com secure app");
System.out.println("Developed By:ISHWAR CHAWAN");
System.out.println("***********************************");
System.out.println("\t1.Display all files");
System.out.println("\t2.Add a new file");
System.out.println("\t3.Delete a file");
System.out.println("\t4.Search a file");
System.out.println("\t5.Exit");
System.out.println("***********************************");
}
/**
* this method will get all the files
*/
public static void getAllFiles()
{
//creating object file
File folder=new File(projectFilesPath);
File[] listofFiles=folder.listFiles();
if(listofFiles.length>0)
{
System.out.println("The Files are listed below:\n");
for(var l:listofFiles)
{
System.out.println(l.getName());
}
}
else
{
System.out.println("The folder is empty");
}
}
/**
* this method will create the files
*/
public static void createFiles()
{
try
{
@SuppressWarnings("resource")
//input from user
Scanner obj= new Scanner(System.in);
String filename;
System.out.println("Enter file name:");
filename=obj.nextLine();
int linescount;
System.out.println("Enter how many lines in the file:");
//storing value
linescount=Integer.parseInt(obj.nextLine());
FileWriter fw=new FileWriter(projectFilesPath+"\\"+filename);
//Read line by line from user
for(int i=1;i<=linescount;i++)
{
System.out.println("Enter file line:");
fw.write(obj.nextLine()+"\n");
}
System.out.println("File created sucessfully");
fw.close();
}
catch(Exception Ex)
{
}
}
/**
* this method will delete the files
*/
public static void deleteFiles()
{
try
{
@SuppressWarnings("resource")
//input from user
Scanner obj= new Scanner(System.in);
String filename;
System.out.println("Enter file name to be deleted:");
filename=obj.nextLine();
//Get all files names into a list
ArrayList <String> allFilesnames=new ArrayList <String> ();
File folder=new File(projectFilesPath);
//reading list of files from the folder
File[] listofFiles=folder.listFiles();
if(listofFiles.length>0)
{
System.out.println("The Files are listed below:\n");
for(var l:listofFiles)
{
allFilesnames.add(l.getName());
}
}
File f=new File(projectFilesPath+"\\"+filename);
if(allFilesnames.contains(filename))
{
f.delete();
System.out.println("File deleted Sucessfully");
}
else
{
System.out.println("File does not exist");
}
}
catch(Exception Ex)
{
System.out.println("unable to delete file.Please contact:admin@test.com");
}
}
/**
* this method search the files
*/
public static void searchFiles()
{
try
{
@SuppressWarnings("resource")
//input from user
Scanner obj= new Scanner(System.in);
String filename;
System.out.println("Enter file name to be Searched:");
filename=obj.nextLine();
//Get all files names into a list
ArrayList <String> allFilesnames=new ArrayList <String> ();
File folder=new File(projectFilesPath);
File[] listofFiles=folder.listFiles();
if(listofFiles.length>0)
{
System.out.println("The Files are listed below:\n");
for(var l:listofFiles)
{
allFilesnames.add(l.getName());
}
}
@SuppressWarnings("unused")
//creating object file
File f=new File(projectFilesPath+"\\"+filename);
if(allFilesnames.contains(filename))
{
System.out.println("File is available");
}
else
{
System.out.println("File is not available");
}
}
catch(Exception Ex)
{
}
}
}