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?
There are several cases of you question, but none of them is language relevant.
Following are something to concern
In c#, you almost do not have a method could be faster than
File.Copywhich invokesCopyFileofWINAPIinternally. 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 fileFurther, if
then, the best thing you can do, is don’t copy files at all.
For example, if your source file lies on
FATorFAT32file system, what you can do isIf your file system was
NTFS, you might need to spend a long time to study the spec.Good luck!