🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #7709

Help with an array?

#7709
From: Alex Colic
Date: Tue, 29 May 2001 14:58
66 lines
2757 bytes
Hi, I am trying to create my own model to populate a JTable. I have a
deliminated text file. An example from the file is:

500005~Electrical~~0~0
500006~Electrician~~1~0.1

I have created a class that reads the file and searchs on a criteria. The
first column above is the criteria. I then populate a vector with the
results. I then need to cast the vector to an array.

My code to read the file and populate the vector is as follows:

public Vector readFile() throws FileNotFoundException, IOException
{
  int n;
  String s;

  Vector objects=new Vector();
  FileInputStream in=new FileInputStream(getFile());

  while((n=in.available())>0)
    {
      byte[] b=new byte[n];
      int result=in.read(b);
      if(result== -1) break;
      s=new String(b);
      String lineSep=System.getProperty("line.separator");
      StringTokenizer fileToken=new StringTokenizer(s,lineSep);
      StringTokenizer lineToken;
      while(fileToken.hasMoreTokens())
        {
          String nextLine=fileToken.nextToken();
          String[] row;
          if(nextLine.startsWith(searchCiteria))
              {
                lineToken=new StringTokenizer(nextLine, "~");
                row=new String[lineToken.countTokens()];
                int i=0;
                while(lineToken.hasMoreElements())
                  {
                    row[i]=lineToken.nextToken();
                    i++;
                  }
                 objects.add(row);
              }
        }
    }
    return objects;
}

As you can see I have a vector 'objects' returned.

My question is the how do I cast that vector to an array?

My original array is as follows:

String [][] theData ={
                                  {"this", "is", "a", "test"}, {"THIS",
"IS", "A", "TEST"}
                                };

Sorry for the long question.

Any help is appreciated.

Alex
Technical Details
Message-ID: <3b13b906_2@dnews>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!news0.de.colt.net!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,1d31711f10772d50,start
X-Google-Attributes: gidf74b3,public
X-Google-ArrivalTime: 2001-05-29 08:20:16 PST
From: "Alex Colic" <alex.colic@pop-ware.com>
Newsgroups: borland.public.jbuilder.java.language
Subject: Help with an array?
Date: Tue, 29 May 2001 10:58:12 -0400
Lines: 72
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4522.1200
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200
NNTP-Posting-Host: 24.150.29.218
Message-ID: <3b13b906_2@dnews>
X-Trace: dnews 991148294 24.150.29.218 (29 May 2001 07:58:14 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!bignews.mediaways.net!news0.de.colt.net!colt.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!dnews