473,382 Members | 1,407 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

stream & streamreader

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(fiPath, FileMode.Open,
FileAccess.ReadWrite,FileShare.None);
System.IO.StreamReader Tin = new System.IO.StreamReader
(stream);
string existText = Tin.ReadToEnd();
fileContent=ReplacementString
(oldStr,newStr,"","",existText);
// OK I HAVE MY NEW STRING...
System.IO.StreamWriter Tout = new System.IO.StreamWriter
(stream);
Tout.Write(fileContent); // 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();

-----Original Message-----
Currently I received a great solution to unique file
access like this:
FileStream stream = null;
stream = File.Open(fiPath, FileMode.Open,
FileAccess.ReadWrite,FileShare.None);

But to read the stream- it seems I have to do this:
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
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
<<StreamReader sr2 = File.OpenText(fiPath);
string foo2= sr2.ReadToEnd();
BUT I cant seem to cast stream into streamReader
( StreamReader sr2 =( StreamReader)stream; // wont work,
cannot convert ....

I have the same issue when it comes to writing the

changesback 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 !!!!


.

Nov 15 '05 #1
1 26600
OK By resetting the position of the stream before the
write and then resetting it again to check the stream
contents I find my updates in the stream, but how to get
them out simply to be written to the file ??

?? maybe I should post as new thread .... and reformulate
the question

-----Original Message-----
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(fiPath, FileMode.Open,
FileAccess.ReadWrite,FileShare.None);
System.IO.StreamReader Tin = new System.IO.StreamReader
(stream);
string existText = Tin.ReadToEnd();
fileContent=ReplacementString
(oldStr,newStr,"","",existText);
// OK I HAVE MY NEW STRING...
System.IO.StreamWriter Tout = new System.IO.StreamWriter
(stream);
Tout.Write(fileContent); // 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();

-----Original Message-----
Currently I received a great solution to unique file
access like this:
FileStream stream = null;
stream = File.Open(fiPath, FileMode.Open,
FileAccess.ReadWrite,FileShare.None);

But to read the stream- it seems I have to do this:
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
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 thestring by doing something like
<<StreamReader sr2 = File.OpenText(fiPath);
string foo2= sr2.ReadToEnd();

BUT I cant seem to cast stream into streamReader
( StreamReader sr2 =( StreamReader)stream; // wont work,
cannot convert ....

I have the same issue when it comes to writing the

changes
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 !!!!


.

.

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ms | last post by:
I'm using streams to upload a file. I get an error 800a0bbc write to file failed. I've looked on support.microsoft.com and groups.google.com. No luck on what a 800a0bbc error is. Thanks
1
by: Guy Korland | last post by:
Hi, 1. How can I read stream in blocking mode? Meaning stop the thread till it get a new line sign? Or getting an event from the stream on new income data? 2. How can I convert 2 bytes to...
9
by: oafyuf | last post by:
Hi, I'm having performanbce issues with StreamReader and was wondering what I could do to improve it... The following takes around 3 seconds to process! The content of the response is: ...
5
by: Anders Olsson | last post by:
I need to create a StreamReader which starts from the position of an existing StreamReader. This way, the second StreamReader can read lines "ahead" in an own loop, and then I can go back to the...
21
by: JoKur | last post by:
Hello, First let me tell you that I'm very new to C# and learning as I go. I'm trying to write a client application to communicate with a server (that I didn't write). Each message from the...
3
by: Arpan | last post by:
A file can be read using only the StreamReader object like this: Dim sReader As StreamReader sReader = New StreamReader(Server.MapPath("File1.txt")) While(sReader.Peek -1)...
0
by: r0swell | last post by:
Hey all, I'm trying to make my app read the stream of a text file and begin at the end of the file. Then parse all the lines that get added in the text file by a other app (Its a log file from a...
7
by: stephcsh | last post by:
Hi, My application is working fine on server A, which is using PHP 4.4.1. However, after it is copied over to server B, which is using PHP 4.4.6, I got several problems related to pdf and xml. ...
6
by: khajeddin | last post by:
hi: i have a program which should read and werite on a file but after the first time it writeon the file it can read te records.but other times it write on the file but just read the records which...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.