So I have a text file that has some info about courses such as course CRN, course full name, course description, course credits. And there are many more courses like this in the file in lines of 4 separated by a new line. I need to save each line into a string to later pass into a constructor so I can store them in a hashmap. Also after each new line it will know that a new course information has started. But I am not much familiar with the buffered reader to do that. I so far just have it that it can read and output each line but I need to save each line (CRN to CRN, name to name, etc) here is what I have so far:
method in question:
public void addCourses() {
String sb;
try(BufferedReader br = new BufferedReader(new FileReader("testC.txt"))) {
while((sb = br.readLine()) != null) {
System.out.println(sb); //just prints out all lines identical to text file
//Do stuff here?
}
} catch(Exception e) {
e.printStackTrace();
}
}
text file looks something like this:
MAT205
Discrete Mathematics
description here
4.0
MAT210
Applied Linear Algebra
description here
3.0
...and so on
Thanks for any help sorry if I am explaining stuff bad, first question on here
Edit: Yes I already have a defined Course class with all getters and setters and appropriate fields.