-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
114 lines (111 loc) · 4.2 KB
/
Main.java
File metadata and controls
114 lines (111 loc) · 4.2 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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package freshworks;
import java.io.File;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author Naveen
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int choice,flag,i=1,f_no=1;
String files="";
Scanner s=new Scanner(System.in);
System.out.println("---------------------------------------------");
System.out.println(" WELCOME TO FILE BASED KEY VALUE DATA STORE");
System.out.println("---------------------------------------------");
do{
System.out.println("1 for create\n2 for append in existing file\n3 for read\n4 for delete");
System.out.print("Enter your choice:");
choice=s.nextInt();
switch(choice)
{
case 1:
System.out.println("--------");
System.out.println(" CREATE ");
System.out.println("--------");
String filename;
System.out.println("1 for Default Location\n2 for User Location and enter the FileName");
int cho=s.nextInt();
if(cho==2)
{
System.out.println("Enter the file:");
filename=s.nextLine()+s.nextLine();
}
else
{
filename="default"+i+".json";
i+=1;
}
files+="\n"+f_no+")"+filename;
f_no+=1;
Create c=new Create();
File file=new File(filename);
try {
file.createNewFile();
System.out.println("File created and the file name is "+filename);
}
catch (IOException ex)
{
ex.getStackTrace();
}
c.create(filename);
break;
case 2:
System.out.println("-------------------------");
System.out.println(" APPEND TO EXISTING FILE ");
System.out.println("-------------------------");
String filename1;
System.out.println("File created are:"+files);
System.out.println("Enter the file:");
filename=s.nextLine()+s.nextLine();
Append ap=new Append();
File file_ap=new File(filename);
try {
file_ap.createNewFile();
System.out.println("File created and the file name is "+filename);
}
catch (IOException ex)
{
ex.getStackTrace();
}
ap.append(filename);
break;
case 3:
System.out.println("--------");
System.out.println(" READ ");
System.out.println("--------");
System.out.println("Files created are:"+files);
System.out.println("Enter the file name to read:");
String f=s.next();
Read r=new Read();
r.read(f);
break;
case 4:
System.out.println("--------");
System.out.println(" DELETE ");
System.out.println("--------");
System.out.println("Files created are:"+files);
System.out.println("Enter the file name to read:");
String f1=s.next();
Delete d=new Delete();
d.delete(f1);
break;
default:
System.out.println("Invalid choice");
}
System.out.print("\n1 for continue\n0 for exit\nDo you want to continue:");
flag=s.nextInt();
}
while(flag==1);
}
}