Results 1 to 3 of 3
  1. #1
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,066
    Rep Power
    8

    Default file stuff and tokens

    any help please concerning file reading and tokens:

    This is the monitor output:

    0 ddtop341;.90;.10;.9;.1640;.940 next token true my comment -> which is the first file line
    file loaded! first read next token false -> before new: s = in.readLine();
    0 232;.true;.true;.true next token false -> after: s = in.readLine();
    file loaded! second read -> the file to read has 100 line! but the
    BUILD SUCCESSFUL (total time: 4 seconds) -> but the t.hasMoreTokens() goes false (one me)

    But what than happens I do not understand (see code fragment here)
    At the upper part of the method one reads of course:
    String s = in.readLine(); // for the first file line to read
    StringTokenizer t = new StringTokenizer(s, ";.");


    Java Code:
    System.out.println(" file loaded! first read next token " + t.hasMoreTokens());
    s = in.readLine();
    System.out.println(panelcount + "  " + s + " next token " + t.hasMoreTokens());
    
                while (t.hasMoreTokens()  ) { //|| panelcount==index
            
                    System.out.println(panelcount + "  " + s);
                    
                    JPanel panel = singlepanel.CreateSingleRoomPanel(new JPanel(),
                         panelcount, (t.nextToken()), // roomnumber string
                                (Boolean.parseBoolean(t.nextToken())), //pf flag
                                (Boolean.parseBoolean(t.nextToken())), //chamberm falg
                                (Boolean.parseBoolean(t.nextToken()))); //disabled flag
    
                    panels.addMouseListener(Mhandler);
                    dynamicinfo[panelcount].setPanelRef(panels);
                   roompanel.add(panels);
                   s = in.readLine();
                   panelcount++;
                }
                System.out.println(" file loaded! second read");
                return roompanel;
          }
    Last edited by willemjav; 03-30-2013 at 08:01 PM.

  2. #2
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,066
    Rep Power
    8

    Default Re: file stuff and tokens

    who says that java is easy to learn?
    BTW there are four tokens on each line, one of string and three of boolean

    So the principle question is why does the t.hasMoreTokens()) goes false, at line 3
    when line 2 reads in a fresh, full line of tokens......
    (see line three of the monitor output please)
    since the t.hasMoreTokens()) is false on does not even get into the while loop!!!
    Last edited by willemjav; 03-30-2013 at 08:00 PM.

  3. #3
    willemjav is offline Senior Member
    Join Date
    Dec 2007
    Location
    Spain
    Posts
    1,066
    Rep Power
    8

    Default Re: file stuff and tokens

    Ok one should t = new StringTokenizer(s, "|"); for each line to read, right?

Similar Threads

  1. tokens from StringTokenizer
    By programcı in forum New To Java
    Replies: 1
    Last Post: 04-05-2011, 04:36 PM
  2. Looping through tokens
    By Landon in forum New To Java
    Replies: 1
    Last Post: 09-12-2010, 11:34 AM
  3. Indexing tokens
    By peliukasss in forum Lucene
    Replies: 4
    Last Post: 08-06-2010, 01:40 AM
  4. tokens
    By Gilgamesh in forum New To Java
    Replies: 5
    Last Post: 12-02-2007, 11:30 PM
  5. tokens
    By Gilgamesh in forum New To Java
    Replies: 3
    Last Post: 11-25-2007, 02:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •