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 4599440
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:32:28+00:00 2026-05-21T23:32:28+00:00

Currently, I am reading data from a binary file (File.ReadAllBytes), converting this byte array

  • 0

Currently, I am reading data from a binary file (File.ReadAllBytes), converting this byte array into a string and appending data onto this string. Lastly, I am converting the string back into a byte array and writing the data back into a new file.

Yeah – this method is fairly idiotic, and I’ve been curious as to whether or not there is some way to append this new data onto the end of the byte array (in the form of a byte).

String s = @"C:\File.exe";
Byte b[] = File.ReadAllBytes(s);

String NewString = ConvertToString(b[]);

NewString = NewString + "Some Data";

b[] = ConvertToByteArray(NewString);
File.WriteAllBytes(b[]);

// ConvertToByteArray and ConvertToString represent functions that converts string > Byte > string.

What I would like to do:

b[] = file.readallbytes(s)
b = b + "new Data"
file.writeallbytes(b[])

Thank you very much for any insight on the matter.

  • 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-05-21T23:32:29+00:00Added an answer on May 21, 2026 at 11:32 pm

    You should get used to working with Streams – in this case you could use a MemoryStream to achieve the exact same thing without all those nasty arrays.

    byte[] bytes = File.ReadAllBytes(inFilePath);
    using (MemoryStream ms = new MemoryStream())
    {
        // You could also just use StreamWriter to do "writer.Write(bytes)"
        ms.Write(bytes, 0, bytes.Length);
    
        using (StreamWriter writer = new StreamWriter(ms))
        {
            writer.Write("Some Data");
        }
    
        File.WriteAllBytes(outFilePath, ms.ToArray());
    }
    

    Admitedly this looks a whole load more complicated than your code, but under the covers what it’s doing is more efficient.

    Of course if you are just writing to another file (or even the same file) you can simply write directly to the file and skip the need for a byte array or MemoryStream entirely – this is the beauty of streams.

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

Sidebar

Related Questions

Currently, I have been reading lists of data from a binary data file programmatically
I'm reading binary data from a file, specifically from a zip file. (To know
I try to write and read object of class into and from binary file
I am currently reading an image from an SQL Server database as byte[]. I
I am currently reading Beginning CakePHP:From Novice to Professional by David Golding. At one
Android 2.1 update 1 Eclipse 3.5 I have a problem reading data from my
I'm trying to get into MVC and currently reading the wrox professional ASP.NET MVC
Currently reading quite a heavy WCF book. I have used it myself in production
I'm currently reading, Design Patterns:Elements of Reusable Object-Oriented Software by Erich Gamma and others.
I'm currently evaluating CodeRush and one thing that I liked most when reading the

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.