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

  • SEARCH
  • Home
  • 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 8349357
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:58:15+00:00 2026-06-09T07:58:15+00:00

Ok, So I am writing another program for the purpose of manipulating binary files.

  • 0

Ok, So I am writing another program for the purpose of manipulating binary files. This program is importing a file larger than anything I have had to manipulate before, about 12K.

I’m curious as to how the Stream.read command works….I know that this sounds elementary, but how can I tell that the file has been read completely so that I can begin manipulating it, as of right now I have this code…

// Opens a stream to the path chosen in the open file dialog
using (FileStream stream = new FileStream(chosenFile, FileMode.Open, FileAccess.Read))                     
{
    size = (int)stream.Length; // Returns the length of the file
    data = new byte[size]; // Initializes and array in which to store the file
    stream.Read(data, 0, size); // Begins to read from the constructed stream
    progressBar1.Maximum = size;

    while (byteCounter < size)
    {
        int i = data[byteCounter];

        byteCounter++;
        progressBar1.Increment(1);
    } 
}

I Understand that this is very very simple, but can someone explain to me how stream.Read works, does it store everything into the byte array “data” and then I can manipulate that as I see fit, or do I have to manipulate the file as it is being read. Again I apologize if this is elementary, all thoughts are appreciated

  • 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-09T07:58:17+00:00Added an answer on June 9, 2026 at 7:58 am

    This line

    stream.Read(data, 0, size); 
    

    reads everything from the stream and stores the file content in your byte array
    You can start working immediately on the array.

    See FileStream.Read docs on MSDN

    Your code reads the length of the file, allocate a byte array of the correct size, then reads everything in a single shot.
    Of course this method is not viable if your file is really big.
    (and the definition of ‘big’ could be different compared to the available memory).
    In that case the approach used is to read chunks of the file, processing and looping till all the bytes are read.

    However, DotNet has specialized classes for reading and writing binary files.
    See the documentation on BinaryReader

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

Sidebar

Related Questions

I'm writing to a file for another program (gnuplot) to use as input. g
My program that I am writing's purpose arose with this issue: There are two
I'm writing a plug-in for another program in C#.NET, and am having performance issues
I am writing a program that processes the output of another program. Assume my
I am writing a program to assemble code for another dynamic program written in
I am trying to read characters from a file and writing them to another.
I am writing a PHP code that creates another PHP file with fopen and
If you are writing some SIMD code that will be run by another program,
I am writing an output module to visualize my data on another program. If
I'm writing a c# application which uses automation to control another program. Naturally that

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.