Author |
Message |
JayLo
|
Posted: Wed Dec 15, 2004 11:01 pm Post subject: Finding how many lines are in a text file? |
|
|
I'm trying to find out how many lines are in a text file, so i know how big my array should be. Actually, is there a more efficient way of getting data, casting it into an Array/Vector with the correct dimensions? |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Wed Dec 15, 2004 11:02 pm Post subject: (No subject) |
|
|
Vectors resize themselves, so you can just keep on feeding data into one. |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
JayLo
|
Posted: Wed Dec 15, 2004 11:08 pm Post subject: (No subject) |
|
|
Yeah, Vectors seem to be better.
The fileStream still isn't reading in all the lines of text in the file.
code: |
while ((c=in.read())!=-1)
{
line = input.readLine ();
st = new StringTokenizer (line);
while (st.hasMoreTokens ())
{
a.add(st.nextToken());
b.add(st.nextToken());
c.add(st.nextToken());
d.add(st.nextToken());
}
}
|
where a, b, c, d are Vectors |
|
|
|
|
|
Tony
|
|
|
|
|
wtd
|
Posted: Wed Dec 15, 2004 11:50 pm Post subject: (No subject) |
|
|
Keep different things different! Read the file in in one place, and tokenize the various strings in another. |
|
|
|
|
|
Martin
|
Posted: Wed Dec 15, 2004 11:55 pm Post subject: (No subject) |
|
|
If the file is just a square of text, you could find out how big one line is, compare that to the size of the text file, and calculate the number of lines. |
|
|
|
|
|
wtd
|
Posted: Thu Dec 16, 2004 9:09 am Post subject: (No subject) |
|
|
martin wrote: If the file is just a square of text, you could find out how big one line is, compare that to the size of the text file, and calculate the number of lines.
You know what they say about assuming... |
|
|
|
|
|
Tony
|
Posted: Thu Dec 16, 2004 6:22 pm Post subject: (No subject) |
|
|
well in programming you can safely assume that the user is intellectually challanged and will actually try to break your program |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
Sponsor Sponsor
|
|
|
|