473,394 Members | 1,889 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,394 software developers and data experts.

Wite and Read to same file ERROR ?

I'm using StreamWriter to write to file and at the same time I'm using the
StreamReader to read from the same file.
Doing that cause an exception when I'm trying to create the StreamReader
when the file is already opened fro writing by the StreamWriter.

How can I write and read at the same time to the same file?

--
Thanks
Sharon G.
Nov 17 '05 #1
3 1840
Thats because StreamReader already opens the File as Read&Write exclusive
(although is can only read from the file, I posted this as bug to MS but
they said they won't solve it for some reason I don't understand).
You have to use another method for opening the file for example File.Open so
you can read&write.

"Sharon" <Sh****@discussions.microsoft.com> schrieb im Newsbeitrag
news:4F**********************************@microsof t.com...
I'm using StreamWriter to write to file and at the same time I'm using the
StreamReader to read from the same file.
Doing that cause an exception when I'm trying to create the StreamReader
when the file is already opened fro writing by the StreamWriter.

How can I write and read at the same time to the same file?

--
Thanks
Sharon G.

Nov 17 '05 #2
Thats because StreamReader already opens the File as Read&Write exclusive
(although is can only read from the file, I posted this as bug to MS but
they said they won't solve it for some reason I don't understand).
You have to use another method for opening the file for example File.Open so
you can read&write.

"Sharon" <Sh****@discussions.microsoft.com> schrieb im Newsbeitrag
news:4F**********************************@microsof t.com...
I'm using StreamWriter to write to file and at the same time I'm using the
StreamReader to read from the same file.
Doing that cause an exception when I'm trying to create the StreamReader
when the file is already opened fro writing by the StreamWriter.

How can I write and read at the same time to the same file?

--
Thanks
Sharon G.

Nov 17 '05 #3
Thanks,
I changed my code as you said and it works fine.
Nov 17 '05 #4

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

Similar topics

3
by: John Flynn | last post by:
hi, having problems reading from and writing back to the same file. basically, i want to read lines of text from a file and reverse them and write them back to the same file.. it has to...
22
by: Jason Heyes | last post by:
Does this function need to call eof after the while-loop to be correct? bool read_file(std::string name, std::string &s) { std::ifstream in(name.c_str()); if (!in.is_open()) return false; ...
5
by: Pete | last post by:
I having a problem reading all characters from a file. What I'm trying to do is open a file with "for now" a 32bit hex value 0x8FB4902F which I want to && with a mask 0xFF000000 then >> right...
2
by: GB | last post by:
Hi Everybody! I have 2 different processes/application. One is writing to a file and another is reading from it. For some reason the code doesnt seems to work and gives mscorlib.dll IOException...
0
by: Sharon | last post by:
I'm using StreamWriter to write to file and at the same time I'm using the StreamReader to read from the same file. Doing that cause an exception when I'm trying to create the StreamReader when...
6
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
1
by: oranmeir | last post by:
What i want actually is that when i right click on an element in my HTML file, select "properties" and then build the style of that html element, i want that the details about the position, colors...
3
by: eholz1 | last post by:
Hello PHP Group, I am having trouble setting permissions correctly so that the magickwand api (php 5.2) can read and write images. I usually read a file from one directory, create a magickwand...
0
by: Leo Jay | last post by:
I'd like to read and write the same socket in different threads. one thread is only used to read from the socket, and the other is only used to write to the socket. But I always get a 10022...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.