File.WriteAllBytes and File.ReadAllBytes
-
Good Day, IF File.WriteAllBytes and File.ReadAllBytes does not have the ability to "return" the progress of the operation, say writing a 1GB file, then what are my other options? My major concern is to be able to extract the progress of the byte writing/reading since I am working with really large files. Thanks! :laugh: ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Good Day, IF File.WriteAllBytes and File.ReadAllBytes does not have the ability to "return" the progress of the operation, say writing a 1GB file, then what are my other options? My major concern is to be able to extract the progress of the byte writing/reading since I am working with really large files. Thanks! :laugh: ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Can't you read/write them in chunks of arbitrary size, for example 1mb per chunk? regards
Yes, that is what I'm hoping to achieve. The "older" way to write files. But I need some example codes or a link perhaps. Thank you. ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Good Day, IF File.WriteAllBytes and File.ReadAllBytes does not have the ability to "return" the progress of the operation, say writing a 1GB file, then what are my other options? My major concern is to be able to extract the progress of the byte writing/reading since I am working with really large files. Thanks! :laugh: ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
Hello, Perhaps you can use timer and keep an eye on disk space being consumed... Like: 1. Have a timer //do what you want.. 2. Get free space in hard-disk you are playing with big files 3. Play with files in timer tick check free space again, you do know the size of the file right? use these two and check approximately how much work has been done. HTH! Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Yes, that is what I'm hoping to achieve. The "older" way to write files. But I need some example codes or a link perhaps. Thank you. ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
You can use BinaryReader.Read[^] in a loop, starting with offset 0 until the end of the file is reached, increasing the offset with the chunk size in every loop step. If you wish I can post an example later (unless you won't find one on google or someone else answers in the meantime), I have to leave right now. regards
-
Hello, Perhaps you can use timer and keep an eye on disk space being consumed... Like: 1. Have a timer //do what you want.. 2. Get free space in hard-disk you are playing with big files 3. Play with files in timer tick check free space again, you do know the size of the file right? use these two and check approximately how much work has been done. HTH! Regards, Adeel
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
Hi, That approach won't work, unfortunately. I already tried a similar approach using FileSystemWatcher. The problem is that File.WriteAllBytes() will initially write the full file size. I do not know why.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
You can use BinaryReader.Read[^] in a loop, starting with offset 0 until the end of the file is reached, increasing the offset with the chunk size in every loop step. If you wish I can post an example later (unless you won't find one on google or someone else answers in the meantime), I have to leave right now. regards
Please do so if you have time. Thanks! :-D
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Hi, That approach won't work, unfortunately. I already tried a similar approach using FileSystemWatcher. The problem is that File.WriteAllBytes() will initially write the full file size. I do not know why.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
Why not try out with System.IO.DriveInfo?
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
-
Why not try out with System.IO.DriveInfo?
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
Alright, I'll try it and report back. :)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Good Day, IF File.WriteAllBytes and File.ReadAllBytes does not have the ability to "return" the progress of the operation, say writing a 1GB file, then what are my other options? My major concern is to be able to extract the progress of the byte writing/reading since I am working with really large files. Thanks! :laugh: ;)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
Take a look at the
FileStream
class. That's the basis of reading and writing files, that's what WriteAllBytes, ReadAllBytes and all the different reader and writer classes use to access files. MSDN Library: FileStream class[^]Despite everything, the person most likely to be fooling you next is yourself.
-
Take a look at the
FileStream
class. That's the basis of reading and writing files, that's what WriteAllBytes, ReadAllBytes and all the different reader and writer classes use to access files. MSDN Library: FileStream class[^]Despite everything, the person most likely to be fooling you next is yourself.
Hi Guffa, My problem is that I don't know how to write a bytearray chunk by chunks. Say I already have byte[] Data, and I want to write it 1024 bytes at a time. Regards
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Hi Guffa, My problem is that I don't know how to write a bytearray chunk by chunks. Say I already have byte[] Data, and I want to write it 1024 bytes at a time. Regards
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Use a loop. Example:
int pos = 0;
int left = data.Length;
while (left > 0) {
int len = Math.Min(left, 1024);
stream.Write(data, pos, len);
pos += len;
left -= len;
}Despite everything, the person most likely to be fooling you next is yourself.
Exactly what I needed! Thank you! :)
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.
-
Why not try out with System.IO.DriveInfo?
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.
Adeel Chaudhry wrote:
Why not try out with System.IO.DriveInfo?
Hi, I've tried it and the outcome is also the same as using the FileSystemWatcher.
It is said that the most complex structures built by mankind are software systems. This is not generally appreciated because most people cannot see them. Maybe that's a good thing because if we saw them as buildings, we'd deem many of them unsafe.