What is the C# equivalent for the Java BufferedInputStream and BufferedOutputStream classes?
Asked
Active
Viewed 5,370 times
1 Answers
5
Well, there's the BufferedStream
class (which wraps an existing stream like in Java), but you don't need to use it as often as you would use the equivalent in Java since most in-built streams in .NET use a certain amount of internal buffering.

Ani
- 111,048
- 26
- 262
- 307
-
Get it ! But i get en error when i try wrap a NetworkStream in BufferedStream. The error says it can't implicitly convert BufferedStream to a NetworkStream! Any idea – Kenzo Dec 03 '11 at 07:22
-
@Xris: What code are you using for this? You can't wrap simply by casting, if that's what you're doing... – Ani Dec 03 '11 at 07:24
-
Here is the code: `networStream1 = new BufferedStream(networkStream1)` – Kenzo Dec 03 '11 at 07:35
-
I'm guessing the static type of `networStream1` is `NetworkStream`? Change it to `Stream` or `BufferedStream` or use a different variable of a compatible type just for the buffered stream. – Ani Dec 03 '11 at 07:37
-
You are right! How can i convert or change a `NetworkStream`object to `Stream` object ? – Kenzo Dec 03 '11 at 07:52
-
A `NetworkStream` is already a `Stream` (can be implicitly converted), but it isn't a `BufferedStream`. – Ani Dec 03 '11 at 07:53
-
You can find a sample in [MSDN](http://msdn.microsoft.com/en-us/library/system.io.bufferedstream.aspx) – Simon Dec 03 '11 at 09:50