-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pb.java
49 lines (49 loc) · 1.15 KB
/
Pb.java
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
import java.io.*;
import java.util.*;
class Pb {
public static void main(String args[])
throws IOException
{
Properties ht = new Properties();
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String name, number;
FileInputStream fin = null;
boolean changed = false;
try {
fin = new FileInputStream("phonebook.dat");
} catch(FileNotFoundException e) {
}
try {
if(fin != null) {
ht.load(fin);
fin.close();
}
}
catch(IOException e) {
System.out.println("Error reading file.");
}
do {
System.out.println("Enter new name"+" ('quit' to stop): ");
name = br.readLine();
if(name.equals("quit")) continue;
System.out.println("Enter number: ");
number = br.readLine();
ht.put(name, number);
changed = true;
} while(!name.equals("quit"));
if(changed)
{
FileOutputStream fout = new FileOutputStream("phonebook.dat");
ht.store(fout, "Telephone Book");
fout.close();
}
do {
System.out.println("Enter name to find" +"('quit' to quit): ");
name = br.readLine();
if(name.equals("quit")) continue;
number = (String) ht.get(name);
System.out.println(number);
} while(!name.equals("quit"));
}
}