• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading the Portion of the file with the line numbes.

 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have to read a file contents which size range from 100 KB to 200MB.This file contain the data of packet transmission between the system interfaces.
So the file may contain 100 to 800000 lines (data). I have to parse each line and to draw in some format based on each line data.The file will be on the
server.I have to read it from a thin java client through servlet or web service.

As i am new to java i am not aware of IO streams. I planned in such a way
1) Using linux command through rt.exerc() and find the total lines of the file which will be sent to client.
2) The client will create the page link based on the line count (a page may display 300 data)
3) Based the page clicked i need to fetch the contents of the specified portion of the file.Suppose if user clicks
the link 20 i have fetch the file content between the lines 5700 to 6000.


Is there any way to read a specified portion of the file using line numbers with out reading the full content of the file.
Please suggest me some right way of doing this.Thank you.

Regards
Ganesh M




 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use the RandomAccessFile class IF you knew precisely the byte offset within the file where each line starts. If all lines have exactly the same length, then it's easy to calculate that offset. But if the lines have different lengths, and the lengths are unknown, then this is not possible.
 
Ganesh kumar
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer .

The data will vary in size for every line.So i think i cannot use RandomAccessFile. Is it feasible to use a concurrent hashmap in a following way
1) Call a reader thread from a main with the panel object as a arguement.
2) The panel object is where i will drraw some sequence based on data
3) The reader thread will read and update the concurrent hashmap.
4) At a regular interval the reader thread will call the paint method of the Jpanel.of Main thread
5) The jPanel paint method will inturn read the concurrent hashmap data and paint the sequence.

I am not sure this approach will work or not.Kindly suggest me if any other better way is there to do.Thank you.

Regards
Ganesh M
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!