GeeCON Prague 2014*
The moose likes Java in General and the fly likes using BufferedReader and looping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "using BufferedReader and looping" Watch "using BufferedReader and looping" New topic
Author

using BufferedReader and looping

vasu singla
Greenhorn

Joined: Dec 20, 2004
Posts: 4
I am using BufferedReader to read through a csv file, there could be 100,00 rows or may be half million rows in the csv file. I have following questions:

1. is BufferedReader an efficient way to read the file and process the data
2. how do i stop at each 25,000 row --> do some processing, then come back again further from the BufferedReader. I am not able to mark the BufferedReader properly to read next 25,000 records after i have read first 25,000 records

flow of my program is as follows:

for(loop through n number of csv files)
{
in = new BufferedReader(new FileReader(fname));

read the 1st line of the csv file to retrieve the header info.

while (ln = in.readLine())!= null) // read through next 25,000 records
{
add all the records in an Array
break out of while as soon as i have read 25,000th record
}

do some processing with the data stored in array above

if there are more than 25,000 records go back to the next 25,000 //HAVING trouble with this implementation of going back and read through next 25,000
else go to next csv file in the loop

}

any help is appreciated
thanks
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Break the application up into logical methods for each step. An exmple using pseudo-code:


By breaking this down into seperate methods, it makes it easy to gain the finctionality you want.

I used pseudo-code to do this, stepping back and using some form of analysis to get through a problem helps. This anaylsis could also be done using a Sequence Diagram to determine calls in the system and identifying methods a class needs to perform a function.


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
vasu singla
Greenhorn

Joined: Dec 20, 2004
Posts: 4
thanks carl
will try to implement this
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: using BufferedReader and looping