Вы можете использовать FileReader для чтения построчно. Затем вы можете разделить полученную строку на запятую и использовать Double.valueOf для получения ваших значений. Следующий пример прост, но предполагает, что файл сформирован правильно:
public class Test {
static class Student {
private String firstName;
private String lastName;
private double math;
private double english;
private double computerScience;
public Student(String firstName, String lastName, double math,
double english, double computerScience) {
this.firstName = firstName;
this.lastName = lastName;
this.math = math;
this.english = english;
this.computerScience = computerScience;
}
@Override
public String toString() {
return "Name: " + firstName + " " + lastName + ", Math: " + math +
", English: " + english + ", Computer Science: " + computerScience;
}
}
public static void main(String[] args) {
BufferedReader reader;
try {
reader = new BufferedReader(new FileReader("/home/username/grades.txt"));
String line = reader.readLine();
while (line != null) {
String[] gradeArray = line.split(",");
Student myStudent = new Student(gradeArray[0], gradeArray[1],
Double.valueOf(gradeArray[2]), Double.valueOf(gradeArray[3]),
Double.valueOf(gradeArray[4]));
System.out.println(myStudent.toString());
line = reader.readLine();
}
}
catch (NumberFormatException|IndexOutOfBoundsException badFile) {
System.out.println("You have a malformed gradebook");
badFile.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}