-
Notifications
You must be signed in to change notification settings - Fork 0
/
Search.java
64 lines (52 loc) · 1.45 KB
/
Search.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import java.util.*;
import java.io.*;
public class Search {
static String text, extra;
static int number;
static double decimal;
static Contacts[] contacts = new Contacts[500];
// static String input_file = "data/temp.txt"; //relative path
static String input_file = "c:/data/addrbook.csv";
// public static void main(String[] args) {
// if (args.length > 0)
// input_file = args[0]; // if arg0 is provided, take it instead
//
// System.out.println("Read data from a file... \n");
try {
File inputFile = new File(input_file);
Scanner input = new Scanner(inputFile);
int row = 1;
int num = 0;
while (input.hasNext()) {
String record = input.nextLine();
String[] tokens = record.split(",");
if (tokens.length == 8) {
String firstname = (tokens[0]);
String lastname = (tokens[1]);
String address = (tokens[2]);
String city = (tokens[3]);
String state = (tokens[4]);
String zipcode = (tokens[5]);
String phone = (tokens[6]);
String etc = (tokens[7]);
contacts[num] = new Contacts(firstname, lastname, address,
city, state, zipcode, phone, etc);
num++;
} else {
System.out.println("Row " + row
+ " skipped (record not complete)");
}
row++;
}
input.close();}
catch (IOException e) {
System.out.println(e);
}
// Printing Student Array
for (Contacts p : contacts) {
if (p != null) {
System.out.println(p.toString());
}
}
}
}