I am trying read text from a .txt file called "Marks.txt" (I attached the file here-> Marks.txt) which contains student data, Like this, thefirst 2 rows are headers or just labels for the data
The first two lines are just headers or labels as stated above, and I'm trying to skip or ignore these lines because I only need to create objects from the actual int and float data in the .txt file. Here is my loadFrom method in my Student class:
public static Student loadFrom2(BufferedReader aFile) throws IOException {
Student newStudent = new Student();
StringTokenizer st = new StringTokenizer(aFile.readLine());
newStudent.ID = Integer.parseInt(st.nextToken());
newStudent.a1 = Float.parseFloat(st.nextToken());
newStudent.a2= Float.parseFloat(st.nextToken());
newStudent.a3 = Float.parseFloat(st.nextToken());
newStudent.a4 = Float.parseFloat(st.nextToken());
newStudent.midterm = Float.parseFloat(st.nextToken());
newStudent.finalExam = Float.parseFloat(st.nextToken());
return (newStudent);
}
and here is my test file that reads the data:
private static void readTest2() throws IOException {
BufferedReader file1;
Student student1;
String line;
file1 = new BufferedReader(new FileReader("C:\\Marks.txt"));
student1 = Student.loadFrom2(file1);
System.out.println(student1);
}
public static void main(String[] args) throws IOException {
readTest2();
}
I took the Marks.txt file and remove the first two lines (headers or column labels) and was able to properly use the BufferedReader and StringTokenizer in my loadFrom2 method to read the .txt file in my readTest2 file.
Can any of you guys tell me how to skip the first 2 lines? I'm supposed to be reading from Marks.txt and creating a Student object in the loadFrom2 method for each line of data in the Marks.txt file. I'm supposed to then have another class called CourseSection is has an ArrayList of objects from the previous class.
Please let me know if I need to clarify anything. Here are the full class files if you want to see:
StudentSaveLoadTest *to test reading the Marks.txt file