The Artima Developer Community
Sponsored Link

Java Answers Forum
Problem with program - string array & tokenizers

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Leslie Jo

Posts: 22
Nickname: leeloo
Registered: Jul, 2002

Problem with program - string array & tokenizers Posted: Jul 20, 2002 2:17 PM
Reply to this message Reply
Advertisement
Hello, i have a problem with this program. I read a file and stored each line in an array of strings. I am trying to write another method but i cant get at the individual strings made by the stringtokenizer. how do i get each of this data out of this thing?


public static void loadDB (String filename)
{
try
{
// find length of file to be read
BufferedReader in = new BufferedReader (new FileReader (filename));
String line = in.readLine ();
size = 0;
while (line != null)
{
line = in.readLine ();
size++;
}
in = new BufferedReader (new FileReader (filename)); // reset bufferedreader
in.close ();


//read an array of data
//retrieve array size
size = Integer.parseInt (in.readLine ());


// set allCities array size
CityLocation [] allCities = new CityLocation [size];

// declare variables
String prov;
String city;
int latDeg;
int latMin;
int longDeg;
int longMin;

for (int i = 0 ; i < size ; i++)
{
allCities = new CityLocation ();
String str = in.readLine ();

// extract individual tokens delimited by ","
StringTokenizer t = new StringTokenizer (str, ",");
prov = t.nextToken ();
city = t.nextToken ();
latDeg = Integer.parseInt (t.nextToken ());
latMin = Integer.parseInt (t.nextToken ());
longDeg = Integer.parseInt (t.nextToken ());
longMin = Integer.parseInt (t.nextToken ());
} // end for

}

Topic: using javascript ,html&combo boxes months,dates example.Pls help me. Previous Topic   Next Topic Topic: quick example please

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use