473,399 Members | 4,254 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,399 software developers and data experts.

Flush() and Close()

guy
I can't find this in the documentation so I'm asking it here:

I assume that if I call Close() on a Stream based class that Flush() does
not need to be called before as it is implicitly called by Close()?

Thanks
Nov 16 '05 #1
3 22417
That is correct.

When you close the stream any remaining buffered content is written out at
that point, otherwise that data would be lost.

Chris.

"guy" wrote:
I can't find this in the documentation so I'm asking it here:

I assume that if I call Close() on a Stream based class that Flush() does
not need to be called before as it is implicitly called by Close()?

Thanks

Nov 16 '05 #2
guy <wi*********@hotmail.com> wrote:
I can't find this in the documentation so I'm asking it here:

I assume that if I call Close() on a Stream based class that Flush() does
not need to be called before as it is implicitly called by Close()?


Yup.

For most streams (CryptoStream excepted due to a bug) you can just call
Dispose instead, which is much easier with a using statement:

using (Stream x = ...)
{
....
} // Dispose called automatically here

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Hi guy,

Calling System.IO.Stream.Close on a Stream flushes any buffered data,
essentially calling System.IO.Stream.Flush for you. System.IO.Stream.Close
also releases operating system resources such as file handles, network
connections, or memory used for any internal buffering.

Nirosh.
"guy" <wi*********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I can't find this in the documentation so I'm asking it here:

I assume that if I call Close() on a Stream based class that Flush() does
not need to be called before as it is implicitly called by Close()?

Thanks

Nov 16 '05 #4

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

Similar topics

4
by: Tony | last post by:
OK - let's get the IE bashing out of the way... <space provided to bash IE> </space> On to the problem: I have a query that I'm running on a test server that takes awhile to
2
by: Philipp | last post by:
Hello, just a simple question: Does the close() method of an ofstream object always flush the buffer? Thanks for answers. Phil
2
by: Someonekicked | last post by:
hi, i cant come to find a solution for a problem in my program, I made an example of the problem; in the example i made, the problem is if happy.dat does not exist, so (!inData) will be true, and...
0
by: ruhunu Gamarala | last post by:
Hi, I get the following exception periodically. does anybody what is the reason for it to throw this exception? I really appriciate if anyone can help me on this. thanks, Chinthaka at...
1
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a...
1
by: Tom | last post by:
Do I really need to flush a streamwriter? It appears to work either way. Dim sw As StreamWriter Dim strFullPath As String = "C:\Temp\Test.txt" If File.Exists(strFullPath) Then sw =...
1
by: r0main | last post by:
Hi, I'm facing an issue to send data throught the HttpWebRequest processing, I'm using the Method POST with a multipart form/data. While writing a file, my application is buffering the whole...
6
by: tegdim | last post by:
Hello, I'm trying to send a string to a subprocesses' output stream in my java program. I'm writing the data to the stream and then trying to flush the stream. This, however , isn't actually...
5
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
(a little more info) after flushing the line (instead of closing streamwirter) it takes some x time to flush the line so, when I read from the file I cannot find the last written line. if I...
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: 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?
0
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,...
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
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...
0
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...

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.