I've current got a file which I'm trying to read and extract data from. I'm using LineNumberReader, StringTokenizer and InputStreamReader to do this.
I've not had any problems for most of the file, however when I get to read the header1 (see below) section of the file I seem to be getting errors. I have written the following code (see below).
When I run it, it prints the first line correctly, altough the next lines mises the first number but prints the following numbers. I'm therefore not sure what I'm doing wrong, also how can I remove the commas?
Thanks in advance for your help.
<< File contents >>
SomeHeader = 334;
# can be random amount of values
header1 = 40.0, 120.0, 50.0, 120.0, 63.0, 120.0, 80.0,
120.0, 100.0, 120.0, 125.0, 120.0, 160.0, 120.0, 200.0,
120.0, 250.0, 118.0, 315.0, 117.0, 400.0, 116.0, 500.0
630.0, 114.0, 800.0, 113.0, 1000.0, 112.0, 1250.0,
header2 = "Blah"
private void extractHeader1()
{
StringTokenizer st = null;
String nextTokenStr = null;
while ( (line = lnr.readLine()) != null)
{
st = new StringTokenizer(line);
if(st.hasMoreTokens())
{
if(st.nextToken().startsWith("header1"))
{
do
{
// Need to count number of values for
// header1 and add values to array
nextTokenStr = st.nextToken("\t=");
System.out.println(nextTokenStr);
line = lnr.readLine();
st = new StringTokenizer(line);
} while( (!st.nextToken().startsWith("header2"))
&& (st.hasMoreTokens()) );
break;
}
}
}
}