i've been trying to search how do I separate the variable name and content in the txt file and store each in the variable of the object but I can't seem to find one. The code below works only if I don't add the variable names so I'm wondering how can I split it so that I can assign the content of the file to the object.
subjects.txt
id=1 name=biology instructor=John Smith room=2
Java file
public class Subject {
Integer id;
String name;
String instructor;
Integer room;
public void importSubject() throws IOException{
//gets data from file and places it into variable
File list = new File("subjects.txt");
Scanner reader = new Scanner(list);
while (reader.hasNextLine()) {
String [] data = reader.newLine.split("=");
this.id = Integer.parseInt(data[0]);
this.name = data[1];
this.instructor = data[2];
this.room = Integer.parseInt(data[3]);
}
}
}