• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Reading alarge file and wrapping content

 
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have a large file (.txt) of size 2Mb..and i need to read the contents of

that file and parse the file such that a record is read for every 50 chars....

I dont have much idea abt streams..Where shall i start off...

its urgent need 2 complete by today...

Thanks in advance,

Regards
 
Ranch Hand
Posts: 257
Hibernate Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Have a look at this way:

1) Have Reader Interface with read(), ... etc methods.

2) Create a concrete class for each type of record with Reader implementation.

3) Have Factory which will return a record type based on key.


Next,

in main or some other method...

FileStream<forInput2GBFile>
List <listOfRecords>
For all Records
{
Record record=RecordFactory.getRecord(Type);
record.read(FileStream);
listofRecords.add(record);
}

Now you have all records in hand.

Advantages:
------------------------
1) In future you can add more record types.
2) the record implementation is isolated.
3) fully encapsulated.
4) No fixed length as 50 chars. Specify the record length in the record class, so every record may have variable length of record size.
5) If you have any header then it will serve as Type input for Factory.



More inputs are welcome.
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Srinivas,

Actually my requirement is ....

I have a 2GB txt file...having a single line of data....

I need to read this file and write the contents of it into another file

the content has to be written in such a manner that a new line has to be

inserted at the end of 'x' characters...

So how shall i do it...?

Is it enough if i use character streams??

Thnaks in advance

Regards
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For such large files should we use ....character streams or byte streams...??

Am making use of a character buffer...but it is giving me a problem..

Regards
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Post what you have so far so we can see exactly where you are stuck. What does it do or not do that isn't right?
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have the following code...



But it is not able to complete the execution ...i cant see the server log to find the problem...

it was able to read around 1 Gb fine...later it stopped the execution..

What could be the problem...?

Regards
 
A Kumar
Ranch Hand
Posts: 982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Even the output is not properly formatted ....

In windows i tried..its causing a new line after every 100 chars...which is fine

but in solaris...it is giving ouptut in haphazard manner not the 100 chars per line asin windows..

Wonder why?

Regards
 
reply
    Bookmark Topic Watch Topic
  • New Topic