SD without close()

Hello,

How to add data to opened file and after power off file is correct write ?

... data = Serial.read(); myFile.print(data); ...

serial work nonstop as logger I do not want to use: myFileClose(); because open and close file is to slow to add on fly serialdata.

RAW data?

Use the flush() method periodically*. It's equivalent to close() in terms of saving your data.

*Don't fly higher than you're willing to fall.

Only write data that you are willing to lose without closing the file or flushing the buffer. When the buffer gets full (512 bytes), it will be flushed. Without closing the file (which calls flush()), any data in the buffer that has not been flushed to the file will be lost.

PaulS: When the buffer gets full (512 bytes), it will be flushed. Without closing the file (which calls flush()), any data in the buffer that has not been flushed to the file will be lost.

That's not quite the whole story. When the buffer fills it is written to the card. But it won't be accessible in the normal way unless you do a flush() or close() afterward since the FAT won't be updated. You can write millions of bytes to a file and the file will appear to be empty.