Code Comments
Programming Forum and web based access to our favorite programming groups.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.smethod ??) Anyway, neither 1 nor 2 is working for me. Can anyone help please.
Post Follow-up to this messageWhat 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.
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.