Home / DeveloperSection / Forums / Converting a text file to an array in Java

Converting a text file to an array in Java

Pravesh Singh 2024 29-Dec-2014
I'm a beginner at Java and have a list of 25 students that include their name, age, income and IQ in a text file. I'm struggling with how to take this text file and put it in an Array so that I can sort them and such. So far I have:

File myFile = new File ("./src/Project2/StudentList");
Scanner myScan = new Scanner(myFile);
while (myScan.hasNext()) {
    String line = myScan.nextLine();
    Scanner scanner = new Scanner(line);
    while (scanner.hasNext()) {
        String name =;
        String age =;
        String income =;
        String smart =;
        Student students = new Student(name, age, income, smart);

I just want to know the easiest way to go about this. I'm so close, I can feel it! Thanks in advance.

Updated on 30-Dec-2014

Can you answer this question?


1 Answers


Liked By