473,778 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(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();

-----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() ;
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

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 26800
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(fiPat h, FileMode.Open,
FileAccess.Rea dWrite,FileShar e.None);
System.IO.Stre amReader Tin = new System.IO.Strea mReader
(stream);
string existText = Tin.ReadToEnd() ;
fileContent=Re placementString
(oldStr,newStr ,"","",existTex t);
// OK I HAVE MY NEW STRING...
System.IO.Stre amWriter Tout = new System.IO.Strea mWriter
(stream);
Tout.Write(fil eContent); // 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(fiPat h, FileMode.Open,
FileAccess.Re adWrite,FileSha re.None);

But to read the stream- it seems I have to do this:
byte[] b = new byte[1024];
UTF8Encodin g 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 thestring by doing something like
<<StreamReade r sr2 = File.OpenText(f iPath);
string foo2= sr2.ReadToEnd() ;

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

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
3915
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
1740
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 char?
9
12766
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: "<?xml version="1.0" ?><ERROR>ORA-01403: no data found</ERROR>" HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strURIQuery);
5
3061
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 outer loop and the first StreamReader is still where I left it. I have been trying to do this using this code: StreamReader sr2 = sr1 //Where sr1 is the existing StreamReader This seems to work just fine, so I guess this is a supported way...
21
13101
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 server is on one line (\r\n at end) and is formed as - each of which is seperated by a space. Arguments with spaces in them are enclosed in quotations. So, I'm able to open a connection to the server. When I send a message to
3
3113
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) Response.Write(sReader.ReadLine) End While as well as using the FileStream object along with the StreamReader object like this:
0
6996
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 game) and display it in a multiple editbox or richeditbox. Ive tryed somthing like this private FileStream file; private StreamReader stream;
7
21638
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. 1) I got this message when i tried to generate a pdf, with image: getimagesize(http://www.myweb.com/image/photo_2.jpg) : failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found in /var/www/vhosts/myweb.com/httpdocs/folder/myphoto.php...
6
3070
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 has written first time. here is my programs: import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.NoSuchElementException; import java.util.Scanner;
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10292
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3627
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.