This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes Problem with reading a huge text file efficiently Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Problem with reading a huge text file efficiently" Watch "Problem with reading a huge text file efficiently" New topic
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
    
    1

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
    
    5

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
    
    1
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...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem with reading a huge text file efficiently
 
Similar Threads
Database integrity check
String Searching in huge Text file
reading clob
Reading very large files with Java
how many words ?