Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Replacing Text in Large Files
I am using System.IO to read large text files (10GB). Each line in
these files is a record, and the main pupose of this application is to
validate the data. This I do by reading the file line by line and
looping thru the lines and all's fine n dandy. Until now.

Here's where the problem is - for certain records (lines) in a very
few of these files, I need to edit a part of the line. that is..
replace text in the middle for a few files.

The only way I could accomplish this so far was by using a separate
Intermediate file and writing to it. This obviously is not the most
optimized way to do it.

1. What would be ideal would be to edit text while reading the file.

2. If that cannot be done, I could Close the StreamReader and edit
text at that particular position (using StreamWriter.basestream.s
method ??)

Anyway, neither 1 nor 2 is working for me. Can anyone help please.

Report this thread to moderator Post Follow-up to this message
Old Post
sam
11-16-04 11:54 PM


Re: Replacing Text in Large Files
What is it that's not working about #2?

A FileStream should be sable, and if you open it readwrite, you
should be able to pass it into the constructor of a StreamReader and
StreamWriter.  So you read with the reader, and when you come across
something that need to replace, s back to the position and rewrite
it with the writer.

FileStream fs = new FileStream(fpath, FileMode.Open,
FileAccess.ReadWrite);
StreamReader reader = new StreamReader(fs);
StreamWriter writer = new StreamWriter(fs);

*disclaimer: I didn't compile that, nor prove my theory ;-) but it
sounds like it should work *

Hope that helps,
Joel Martinez
Orlando .NET User Group
http://www.onetug.org
http://www.codecube.net

samittaneja@yahoo.com (sam) wrote in message news:<f2fe0738.0411151319.6c5ca09a@posting.goo
gle.com>...
> I am using System.IO to read large text files (10GB). Each line in
> these files is a record, and the main pupose of this application is to
> validate the data. This I do by reading the file line by line and
> looping thru the lines and all's fine n dandy. Until now.
>
> Here's where the problem is - for certain records (lines) in a very
> few of these files, I need to edit a part of the line. that is..
> replace text in the middle for a few files.
>
> The only way I could accomplish this so far was by using a separate
> Intermediate file and writing to it. This obviously is not the most
> optimized way to do it.
>
> 1. What would be ideal would be to edit text while reading the file.
>
> 2. If that cannot be done, I could Close the StreamReader and edit
> text at that particular position (using StreamWriter.basestream.s
> method ??)
>
> Anyway, neither 1 nor 2 is working for me. Can anyone help please.

Report this thread to moderator Post Follow-up to this message
Old Post
Joel Martinez
11-16-04 11:54 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

C# archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:02 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.