-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwaiter.java
More file actions
93 lines (83 loc) · 3.21 KB
/
Copy pathwaiter.java
File metadata and controls
93 lines (83 loc) · 3.21 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
package rms;
import java.util.*;
import java.io.*;
import static java.lang.System.exit;
public class waiter {
public void writefile(String username, String password) {
try {
try (FileWriter mywrite = new FileWriter("D:\\MIU Courses\\Object Oriented Programming/waiter.txt", true)) {
mywrite.write(username);
mywrite.write(password);
}
} catch (IOException ex) {
System.out.println("An error occurred." + ex);
}
}
public boolean searchusername(String username) throws FileNotFoundException {
File file = new File("D:\\MIU Courses\\Object Oriented Programming/waiter.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
if (lineFromFile.contains(username)) {
return true;
}
}
return false;
}
public boolean searchpassword(String password) throws FileNotFoundException {
File file = new File("D:\\MIU Courses\\Object Oriented Programming/waiter.txt");
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) {
final String lineFromFile = scanner.nextLine();
if (lineFromFile.contains(password)) {
return true;
}
}
return false;
}
public void parseFile(String fileName, String searchStr) throws FileNotFoundException { //Search
Scanner scan = new Scanner(new File(fileName));
while (scan.hasNext()) {
String line = scan.nextLine().toLowerCase();
if (line.contains(searchStr)) {
System.out.println(line);
}
}
}
public void deletefile(int choose) {
File myobj = new File("D:\\MIU Courses\\Object Oriented Programming\\waiter.txt");
if (choose == 1) {//handle the error if the user enters letter not a number
if (myobj.delete()) {
System.out.println(myobj.getName() + ":file is deleted successfully");
} else {
System.out.println("unexpected error occured");
}
} else {
exit(0);
}
}
public String delete(String username, String password) {
File myobj = new File("D:\\MIU Courses\\Object Oriented Programming\\waiter.txt");
username = "";
password = "";
return null;
}
public void GetTheOrder() {
try {
String strcurrentline;
BufferedReader myobj = new BufferedReader(new FileReader("D:\\MIU Courses\\Object Oriented Programming\\order.txt"));
try (Scanner myreader = new Scanner(myobj)) {
while ((strcurrentline = myobj.readLine()) != null) {
System.out.println(strcurrentline);
}
int data = myobj.read();
while (data != -1) {
data = myobj.read();
}
myobj.close();
}
} catch (IOException e) {
System.out.println("an error occured");
}
}
}