Arduino File.flush()
Description
The File.flush() function ensures that any bytes written to the file are physically saved to the SD card. This is done automatically when the file is closed.
The File.flush() function inherits from the Stream utility class.
Syntax
file.flush()
Parameters
Returns
- None
Example Code
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/reference/library/arduino-file.flush
*/
#include <SD.h>
#define PIN_SPI_CS 4
File file;
char string[] = "ArduinoGetStarted.com";
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println(F("SD CARD FAILED, OR NOT PRESENT!"));
while (1); // don't do anything more:
}
file = SD.open("arduino.txt", FILE_WRITE);
if (file) {
file.write(string, sizeof(string));
file.flush();
file.close();
} else {
Serial.print(F("SD Card: error on opening file arduino.txt"));
}
}
void loop() {
}
Tutorials
See Also
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables .
Additionally, some links direct to products from our own brand, DIYables .