-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStudentsFile.java
36 lines (29 loc) · 987 Bytes
/
StudentsFile.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
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
public class StudentsFile {
private File file;
public StudentsFile(File file) {
this.file = file;
}
public StudentsFile(String filename) {
this(new File(filename));
}
public List<Student> getStudents() throws IOException {
List<Student> students = new ArrayList<>();
BufferedReader reader = new BufferedReader(new FileReader(file));
for (String line = reader.readLine();
line != null;
line = reader.readLine()) {
String[] student = line.split(",");
students.add(new Student(student[0].trim(),
Integer.parseInt(student[1].trim()),
Float.parseFloat(student[2].trim())));
}
reader.close();
return students;
}
}