| Author |
Problem with reading a huge text file efficiently
|
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
I have a huge text file and my job is to read the content of the file and add those records in a JTable.
Simple reading of such a huge file is very inefficient.
What is the most efficient possible way to solve this issue and please provide an example.
|
 |
Christian Dillinger
Ranch Hand
Joined: Jul 20, 2009
Posts: 172
|
|
|
What is "huge"? How many lines? How many columns? Do you have to show everything in your table or just some fields from each line?
|
 |
buntha Choudhary
Ranch Hand
Joined: Jul 03, 2009
Posts: 136
|
|
consider it is about 50000 lines with having 3 columns.
I need to show all these records but can't use any general reading technique.
|
 |
Stephan van Hulst
Bartender
Joined: Sep 20, 2010
Posts: 3065
|
|
We're talking what 200 - 500 kb here?
Why can't you use a simple BufferedReader? Have you tried it? Doesn't it perform well enough?
|
 |
Christian Dillinger
Ranch Hand
Joined: Jul 20, 2009
Posts: 172
|
|
|
If it's 100 byte per line we are talking about 5 MB! But that's by far not to much hold in memory... I'd read to a List<String[]> and put that list into a simple TableModel.
|
 |
Steve Luke
Bartender
Joined: Jan 28, 2003
Posts: 3090
|
|
You might find using the NIO mapped files a means of speeding up the I/O functions.
|
Steve
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12324
|
|
Wait a second
You are trying to present a swing JTable with 50,000 lines??
How in the name of sanity do you expect somebody to navigate in that?
Isn't there some kind of overall structure you can use to present smaller JTables? Maybe some sort of partial match or alphabetic selection?
Bill
|
Java Resources at www.wbrogden.com
|
 |
J. Insi
Ranch Hand
Joined: Aug 11, 2010
Posts: 83
|
|
i thought that what he did was,
50,000 lines as a total.
But in the application runs... it was divided into several pieces... 100 lines per page perhaps?
well, not sure.
But yes, using the buffer method works fine for reading at the time IO works...
|
 |
 |
|
|
subject: Problem with reading a huge text file efficiently
|
|
|