OK I am half way there - I can manipulate the stream
without the byte issue like this - but is this the way to
push the new values back into the stream & write out the
stream without resorting to byte conversion ??
FileStream stream = null;
stream = File.Open(fiPat h, FileMode.Open,
FileAccess.Read Write,FileShare .None);
System.IO.Strea mReader Tin = new System.IO.Strea mReader
(stream);
string existText = Tin.ReadToEnd() ;
fileContent=Rep lacementString
(oldStr,newStr, "","",existText );
// OK I HAVE MY NEW STRING...
System.IO.Strea mWriter Tout = new System.IO.Strea mWriter
(stream);
Tout.Write(file Content); // just sticks back in the stream
Tout.Close(); // IS THIS ACTUALLY UPDATING THE STREAM ??
Tin.Close();
// how do I persist the revised stream to file ??
stream.Close();
[color=blue]
>-----Original Message-----
>Currently I received a great solution to unique file
>access like this:
>FileStream stream = null;
>stream = File.Open(fiPat h, FileMode.Open,
>FileAccess.Rea dWrite,FileShar e.None);
>
>But to read the stream- it seems I have to do this:
>byte[] b = new byte[1024];
>UTF8Encoding temp = new UTF8Encoding(tr ue);
>string footest;
>while (stream.Read(b, 0,b.Length) > 0)
>footest= temp.GetString( b);
>footest = footest.TrimEnd ('\0');
>int footestlen = footest.Length;
>}
>
>[ I'd prefer to not worry about the size, or trimming the
>string by doing something like
><<StreamRead er sr2 = File.OpenText(f iPath);
>string foo2= sr2.ReadToEnd() ;[color=green][color=darkred]
>>>[/color][/color]
>BUT I cant seem to cast stream into streamReader
>( StreamReader sr2 =( StreamReader)st ream; // wont work,
>cannot convert ....
>
>I have the same issue when it comes to writing the[/color]
changes[color=blue]
>back out. Is it really that messy, or have I overlooked
>teh obvious for simple text IO ( and maintain the unique
>access that stream provides ) THANKS !!!!
>
>
>
>
>.
>[/color]
without the byte issue like this - but is this the way to
push the new values back into the stream & write out the
stream without resorting to byte conversion ??
FileStream stream = null;
stream = File.Open(fiPat h, FileMode.Open,
FileAccess.Read Write,FileShare .None);
System.IO.Strea mReader Tin = new System.IO.Strea mReader
(stream);
string existText = Tin.ReadToEnd() ;
fileContent=Rep lacementString
(oldStr,newStr, "","",existText );
// OK I HAVE MY NEW STRING...
System.IO.Strea mWriter Tout = new System.IO.Strea mWriter
(stream);
Tout.Write(file Content); // just sticks back in the stream
Tout.Close(); // IS THIS ACTUALLY UPDATING THE STREAM ??
Tin.Close();
// how do I persist the revised stream to file ??
stream.Close();
[color=blue]
>-----Original Message-----
>Currently I received a great solution to unique file
>access like this:
>FileStream stream = null;
>stream = File.Open(fiPat h, FileMode.Open,
>FileAccess.Rea dWrite,FileShar e.None);
>
>But to read the stream- it seems I have to do this:
>byte[] b = new byte[1024];
>UTF8Encoding temp = new UTF8Encoding(tr ue);
>string footest;
>while (stream.Read(b, 0,b.Length) > 0)
>footest= temp.GetString( b);
>footest = footest.TrimEnd ('\0');
>int footestlen = footest.Length;
>}
>
>[ I'd prefer to not worry about the size, or trimming the
>string by doing something like
><<StreamRead er sr2 = File.OpenText(f iPath);
>string foo2= sr2.ReadToEnd() ;[color=green][color=darkred]
>>>[/color][/color]
>BUT I cant seem to cast stream into streamReader
>( StreamReader sr2 =( StreamReader)st ream; // wont work,
>cannot convert ....
>
>I have the same issue when it comes to writing the[/color]
changes[color=blue]
>back out. Is it really that messy, or have I overlooked
>teh obvious for simple text IO ( and maintain the unique
>access that stream provides ) THANKS !!!!
>
>
>
>
>.
>[/color]
Comment