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

  • file: an instance of the File class that is returned by SD.open()

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() { }

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.

※ OUR MESSAGES