-
Notifications
You must be signed in to change notification settings - Fork 0
/
FileIO.java
28 lines (25 loc) · 906 Bytes
/
FileIO.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
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class FileIO {
public static List<Customer> readCustomers(String fileName) {
List<Customer> customers = new ArrayList<>();
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader(fileName));
String line = reader.readLine();
while (line != null) {
StringTokenizer tokenizer = new StringTokenizer(line, ",");
customers.add(new Customer(tokenizer.nextToken(), tokenizer.nextToken(), tokenizer.nextToken()));
line = reader.readLine();
}
reader.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e2) {
e2.printStackTrace();
}
return customers;
}
}