2D Array - Loading data from text file with delimit

Discussion in 'Java' started by guss46, May 14, 2009.

  1. guss46

    guss46 New Member

    May 14, 2009
    Likes Received:
    Trophy Points:
    Below is my method im working with, under it is an explanation and question, please help, what am I doing wrong here?

    Thanks :)

    public void searchStudent() throws Exception {
      Scanner scanner;                    //Set Scanner
            scanner = new Scanner(System.in);  
      Student[][] allstudentObjArray = new Student[10][12];
       Scanner allStu = new Scanner(new File("allstudents2.txt"));
       int i=0;
      // boolean found = false;
       //This is where your problem lays your reading it into the wrong thing soilder.
       Scanner sa1 = new Scanner(allStu.nextLine());
        for (int i3 = 0; i3 < allstudentObjArray.length; i3++)
       //Delimit this line with scanner
       for(int i2 = 0;i2 < allstudentObjArray.length;i2++)
        //Try sa1 for stuAll below??
        //Try Student for stuAll below??
        //Try get rid of the "new". why create new object
        allstudentObjArray[i3][i2] = new stuAll(sa1.next());
    Pretty much what Im trying to do here is, go through each line of the text file with values delimited by :
    there are 11 lines, with 13 values in each line all seperated by a ":"
    I want to put these into this 2D array and then take them out for use as needed by my program.
    Im trying to use two for loops, one for the line to go and then one for the values.
    I seem to be doing something wrong, it seems to be happening around the stage when I try to put the delimited value in
    one by one.
    Am I going about this the right way, or should I be heading down a different path?
    Or is there something small I'm just not doing right,
    say around this line "allstudentObjArray[i3][i2] = new stuAll(sa1.next());"

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice