Reading a File --Memory Problem
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   robert_ron
Posted On:   Wednesday, May 28, 2003 03:11 PM


Hi,


I have to read a file which is of large size.So If I read the file,would there any be problem with the memory(at run time) as I'm reading the entire file content or does it not affect anything?


If memory is a problem how would I read the file to extract the contents?


should I read the file and store the file pointer and then resume reading from the saved filepointer and so on?


Any Idea?


--Robert

Re: Reading a File --Memory Problem

Posted By:   Stephen_McConnell  
Posted On:   Friday, May 30, 2003 05:24 AM

If you are just reading and processing a file sequentially, then you don't have a problem.


BufferedReader can wrap a FileReader object and you can read a line at a time (depending upon how the file is delimited).


If you need to read it randomly, RandomAccessFile allows you to create and access a random access file, set record length and a bunch of Random access functions.


The nice thing is that BufferedReader, FileReader and RandomAccessFile (all in the java.io package) keep track of the file pointer for you (if you keep the same Object instance from call to call). Take a look at the JavaDocs for these; and it should help in figuring out how to process the file.


Good luck.


Stephen McConnell

About | Sitemap | Contact