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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:26:36+00:00 2026-06-13T13:26:36+00:00

How can I delete a byte if I have its offset from a FileStream

  • 0

How can I delete a byte if I have its offset from a FileStream and then rewrite it
example:

Offset  00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
DB0     00 00 00 00 00 00 01(byte to delete) 00 .......

I tried this but failed :

byte[] newFile = new byte[fs.Length];
fs.Position = 0;
fs.Read(newFile, 0, va -1);
fs.Position = va + 1;
fs.Read(newFile, 0, va + 1);
fs.Close();
fs.Write(newFile, 0, newFile.Length);

Where va is equal to DB5

  • 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-13T13:26:37+00:00Added an answer on June 13, 2026 at 1:26 pm

    There are some mistakes in the code:

    // the buffer should be one byte less than the original file
    byte[] newFile = new byte[fs.Length - 1];
    fs.Position = 0;
    // you should read "va" bytes, not "va-1" bytes
    fs.Read(newFile, 0, va);
    fs.Position = va + 1;
    // you should start reading into positon "va", and read "fs.Length-va-1" bytes
    fs.Read(newFile, va, fs.Length - va - 1);
    fs.Close();
    fs.Write(newFile, 0, newFile.Length);
    

    However, that way of using the Read method is not reliable. The method can actually read less bytes than you request. You need to use the return value from the method call, which is the number of bytes actually read, and loop until you have got the number of bytes that you need:

    byte[] newFile = new byte[fs.Length - 1];
    fs.Position = 0;
    int pos = 0;
    while (pos < va) {
      int len = fs.Read(newFile, pos, va - pos);
      pos += len;
    }
    fs.Position = va + 1;
    int left = fs.Length - 1;
    while (pos < left) {
      int len = fs.Read(newFile, pos, left - pos);
      pos += len;
    }
    fs.Close();
    fs.Write(newFile, 0, newFile.Length);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can i delete a html-special char \ from a string. $string = 'This
How I can delete an object which I had added before with this code.
I trying to figure out how I can delete from multiple tables in SQL
I have built CMS on cakephp framework. I can delete just one or more
From the documentation: If the platform supports the unsetenv() function, you can delete items
How can I delete the hidden cropped elements from a pdf from command line?
how can I delete IE 8 cookies for a certain site from Python?
I have a system which generates a cookie in PHP, then needs to delete
I have a simple put and get working, but can't seem to find how
I want to Delete and Insert the Record but I have the error which

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.