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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T13:14:24+00:00 2026-06-18T13:14:24+00:00

I am using this code to extract a chunk from file // info is

  • 0

I am using this code to extract a chunk from file

// info is FileInfo object pointing to file
var percentSplit = info.Length * 50 / 100; // extract 50% of file
var bytes = new byte[percentSplit];
var fileStream = File.OpenRead(fileName);
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Dispose();
File.WriteAllBytes(splitName, bytes);

Is there any way to speed up this process?

Currently for a 530 MB file it takes around 4 – 5 seconds. Can this time be improved?

  • 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-18T13:14:25+00:00Added an answer on June 18, 2026 at 1:14 pm

    There are several cases of you question, but none of them is language relevant.

    Following are something to concern

    • What is the file system of source/destination file?
    • Do you want to keep original source file?
    • Are they lie on the same drive?

    In c#, you almost do not have a method could be faster than File.Copy which invokes CopyFile of WINAPI internally. Because of the percentage is fifty, however, following code might not be faster. It copies whole file and then set the length of the destination file

    var info=new FileInfo(fileName);
    var percentSplit=info.Length*50/100; // extract 50% of file
    
    File.Copy(info.FullName, splitName);
    using(var outStream=File.OpenWrite(splitName))
        outStream.SetLength(percentSplit);
    

    Further, if

    1. you don’t keep original source after file splitted
    2. destination drive is the same as source
    3. your are not using a crypto/compression enabled file system

    then, the best thing you can do, is don’t copy files at all.
    For example, if your source file lies on FAT or FAT32 file system, what you can do is

    1. create new dir entry(entries) for newly splitted parts of file
    2. let the entry(entries) point(s) to the cluster of target part(s)
    3. set correct file size for each entry
    4. check for cross-link and avoid that

    If your file system was NTFS, you might need to spend a long time to study the spec.

    Good luck!

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

Sidebar

Related Questions

I'm using this (simplified) chunk of code to extract a set of tables from
I'm using this code to extract text from the database and it works well
While using this code to serialize an object: public object Clone() { var serializer
When using this code (simplified for asking): var rows1 = (from t1 in db.TABLE1
I'm trying to get attributes from an XML file using this code: $xmlFile =
I am using this code to extract the IP Address from a string: preg_match(
I want to extract attributes out of the xml file using this code xml
I'm extracting a file from a zip archive using this code (omitting all the
I am using this code to extract a password protected RAR file. I am
I'm using Boilerpipe to extract text from url, using this code: URL url =

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.