Then program is to display the collected array info on screen formatted appropriately.
But the output on the console is:
110001 commercial 500000.0 101
110020 commercial 1000000.0 107
110442 farm 200000.0 106
112352 residential 250000.0 110
0 null 0.0 0
I'm wondering where the other tokens are going... is the program using \n as a token? It seemed to get only every other line, with a null line at the end.
Thought it was pretty straightforward: each column's token goes into an array as appropriate type (int, double, or string), then advance the array one number and repeat.
I wouldn't do it like this. You put your file into memory completely, but you only need one line at a time. Why not read the file line by line, then parse that line:
On a side note, about your use of StringBuffer:
1) use StringBuilder instead. StringBuffer adds unnecessary synchronization
2) StringBuffer has method append(char[] str, int offset, int len). That means you can call append(buffer, 0, charactersIn), and you don't need to create a new String just for adding it.
That's a valid idea, and is the method I would prefer to use. However, I'm not permitted to use a BufferedReader. It must be unbuffered when being read into the program.
Therefore, I made one big string and then tokenized it. Why though, is it reading basically half the tokens and leaving out the rest? How can I get it to get them from each line and sorted into the appropriate arrays, as it currently does with only every other line of the initial file?
Why must it be unbuffered? You are now essentially creating the biggest buffer there is - the file itself is completely buffered into your StringBuffer.
I know and agree. This is the first of a two-part exercise to show me the difference between unbuffered and buffered FileReaders. The teacher requires this program to be unbuffered. I have a similar exercise next that will have BufferedReader.
I can buffer it AFTER FileReader has done its thing, and so I did to make it easier. I think.
Can you show us your output code? I've just copied your code, added my arrays, then printed it out. I got my input back. After adding formatting to the doubles the file was even identical.
Holy crap I pulled another dumb mistake. Your asking me to post the "displayer" code made me see it.
I was using a "for loop" to go through the arrays to display them on-screen.
However, I also advanced the array line by one INSIDE the loop. Therefore it would show every OTHER line. Which it did.
I am really really sorry for wasting your time with a stupid mistake.
Also, I am very grateful for your help with this. I've been messing with this program for FAR too long, and I guess I just needed another set of eyes to clue me in to my noobie errors.
Thank you!!!
David Spurgeon wrote:I am really really sorry for wasting your time with a stupid mistake.
It's OK. You thought the problem was in one piece of code, and it took me all-in-all less then 10 minutes (including all replies) to conclude it wasn't located there. So not much time was spent, and since you've found the answer it wasn't wasted at all.
Also, I am very grateful for your help with this. I've been messing with this program for FAR too long, and I guess I just needed another set of eyes to clue me in to my noobie errors.
It's quite normal to not see the most simplest of solutions, and I too require a fresh set of eyes sometimes.
Thank you!!!
You're welcome.
Post by:autobot
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
a bit of art, as a gift, the permaculture playing cards