I'm facing problems when reading large files. I have some code that copies one file from a USB stick to an SD Card. But I'm facing issues when copying large files, larger than 10MB. Here is how I'm doing it:
- I open the file I want to copy in the "source" media as "r"
- I open a file on the "dest" device with attributes as "wb"
- I allocate an 8192 byte buffer that is the one I will use for reading from the source file and writing to the destination file.
- I read 8192 bytes from the source file and write them to the destination file. I do this as many times as bytes there are.
Everything goes well for the first couple of megs, but then randomly, the "read" function returns 0 and the source device stops responding, even when I close the file and try to open it again. I have done this copying successfully with files under 10 MB but it doesn't work with files larger than that. I'm reading from USB and immediately writing to the SD Card without interruption or delays, I don't know if I need to introduce a delay in between read and write or something.
What I'm trying to know if this is the correct way of doing it, just opening both files, read from one and write to the other. I mean, it works just fine for files up to 10MB so I'm not sure.