How to read values from custom txt in Java

I want to read all values from the txt file in Java and assign it to Student object before adding it to List<Student> but I have custom txt file Here is the custom file shown below Student1 Name, Surname, Age Student2 Name, Surname, Age .... How can I do that?
6 Replies
JavaBot
JavaBot3y ago
This post has been reserved for your question.
Hey @direct_x_34! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.
direct_x_34
direct_x_34OP3y ago
Actually my txt like this
Classroom1
Student1 Name, Student1 Surname , Student1 Age
Student2 Name, Student2 Surname , Student2 Age
Student3 Name, Student3 Surname , Student3 Age
Student4 Name, Student4 Surname , Student4 Age
...
Classroom2
Student1 Name, Student1 Surname , Student1 Age
Student2 Name, Student2 Surname , Student2 Age
Student3 Name, Student3 Surname , Student3 Age
Student4 Name, Student4 Surname , Student4 Age
...
Classroom3
...
Classroom1
Student1 Name, Student1 Surname , Student1 Age
Student2 Name, Student2 Surname , Student2 Age
Student3 Name, Student3 Surname , Student3 Age
Student4 Name, Student4 Surname , Student4 Age
...
Classroom2
Student1 Name, Student1 Surname , Student1 Age
Student2 Name, Student2 Surname , Student2 Age
Student3 Name, Student3 Surname , Student3 Age
Student4 Name, Student4 Surname , Student4 Age
...
Classroom3
...
I tried to implement some coding stuff but I couldn't handle with the process. How can I do that? Here is the code snippet shown below.
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // detect inputs from the terminal input, System.in
List<Student> students;
while(in.hasNextLine()) { // while the scanner has a next line
in.nextLine();
String[] s = in.nextLine().split(",");
students.add(new Student(s[0], s[1], s[2]));
}
}
public class Student {
public String name;
public String surname;
public int age;
public Student(String name, String surname, int age) {
// ...
}
}
}
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); // detect inputs from the terminal input, System.in
List<Student> students;
while(in.hasNextLine()) { // while the scanner has a next line
in.nextLine();
String[] s = in.nextLine().split(",");
students.add(new Student(s[0], s[1], s[2]));
}
}
public class Student {
public String name;
public String surname;
public int age;
public Student(String name, String surname, int age) {
// ...
}
}
}
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
JavaBot
JavaBot3y ago
💤 Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived. If your question was not answered yet, feel free to re-open this post or create a new one.
Want results from more Discord servers?
Add your server