Writing binary data from sd card to the Serial port.

I have a csv file stored on an sd card (test.csv). I need to send the file to the serial port as binary and view the number of bytes written.

sample code:
//open the file for reading

myFile = SD.open("test.csv);
if (myFile) {

// read from the file

while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file
myFile.close();
}

according the the reference available on the website, it says write() will return the number of bytes written, though reading that number is optional .

My problem is, how do i get the number of bytes written because my next application entirely depends on this number.

SD read _ write (1.15 KB)

according the the reference available on the website, it says write() will return the number of bytes written, though reading that number is optional .

My problem is, how do i get the number of bytes written because my next application entirely depends on this number.

"My problem is I need to know the number of bytes written." Then, discarding the output of Serial.write() is NOT optional, is it?

int totalBytes = 0; // Start with zip

totalBytes += Serial.write(someStuff); // Add the number written this time.

It ain't rocket surgery.

I don't see why you have to count the characters written to the serial port, when you know how many are in the file.

You should be storing the myFile.read() value in a byte, and then Serial.write()ing that byte, anyway, to assure that only valid data is sent.

hdmafukidze:
thanks a lot i have tried that and it works for stings and integers (below 255) but it does not work for a scv file stored on an sd card.

Then use unsigned long or something else than an int.

Otherwise just use the SD library function to get the file size.

Thats the function i am looking for, if you know you can tell me.

You are already using it...

while (myFile.available())