Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8860387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:15:22+00:00 2026-06-14T15:15:22+00:00

FileStream stream = new FileStream(test,FileMode.Create); BufferedStream buff = new BufferedStream(stream, 8); BinaryWriter writer =

  • 0
FileStream stream = new FileStream("test",FileMode.Create);
BufferedStream buff = new BufferedStream(stream, 8);
BinaryWriter writer = new BinaryWriter(buff);
writer.Write(1);
writer.Write(2);
writer.Write(3);
Console.WriteLine(buff.Length);

As I understand content is flushed when it reaches bufer size in this code 8 bytes.
So why buff.Length returns 12 and why data appears in file only if I explicit call Dispose/Close?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T15:15:23+00:00Added an answer on June 14, 2026 at 3:15 pm

    The BufferedStream works fine – it doesn’t flush: stream.Length is 8 until it is closed; i.e.

    // note these should really use "using" statements of similar
    FileStream stream = new FileStream("test", FileMode.Create);
    BufferedStream buff = new BufferedStream(stream, 8);
    BinaryWriter writer = new BinaryWriter(buff);
    writer.Write(1);
    writer.Write(2);
    writer.Write(3);
    Console.WriteLine(stream.Length); // 8
    Console.WriteLine(buff.Length); // 12
    

    The reason that buff.Length is 12 is because that is the length of the underlying stream. Basically, BufferedStream just re-exposes the stream underneath, and to ensure it doesn’t miss the buffered data it adds a Flush() if there is buffered data:

    public override long Length
    {
        get
        {
            this.EnsureNotClosed();
            if (this._writePos > 0)
            {
                this.FlushWrite();
            }
            return this._stream.Length;
        }
    }
    

    Hence:

    Console.WriteLine(stream.Length); // 8
    Console.WriteLine(buff.Length); // 12
    Console.WriteLine(stream.Length); // 12
    

    Note that the FileStream can have its own buffering too

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FileStream f=new FileStream(c:\\file.xml,FileMode.Create); StreamWriter sf=new StreamWriter(f); sf.WriteLine(stroka); sf.Close(); sf.Dispose(); f.Close(); f.Dispose(); FileStream f1=new FileStream(c:\\file.xml,FileMode.Open);
FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read); Arguments: << path >> Debugging resource strings
If I were reading byte numbers I would do: using (FileStream stream = new
using (var file_stream = File.Create(users.xml)) { var serializer = new XmlSerializer(typeof(PasswordManager)); serializer.Serialize(file_stream, this); file_stream.Close();
I am trying to read data from a file stream as shown below: fileStream.Read(byteArray,
How can I write 'one bit' into a file stream or file structure each
We have a new filestream database that will be initially loaded with 65GB data,
I'm trying to write out to the response stream - but it is failing,
I try to write an xml object via AIR with FileStream.writeObject I'm doing like
Here is a snippet of my code: string filePath = @C:\DRMF.xls; FileStream stream =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.