Arduino File.close()
Description
The File.close() function closes the opened file, and ensure that any data written to it is physically saved to the SD card.
The File.close() function inherits from the Stream utility class.
Syntax
file.close()
Parameters
- File: an instance of the File class that is returned by SD.open()
※ NOTES AND WARNINGS:
If a file is not closed before openning it again, it may fails to 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.close
*/
#include <SD.h>
#define PIN_SPI_CS 4
File file;
void setup() {
Serial.begin(9600);
if (!SD.begin(PIN_SPI_CS)) {
Serial.println("SD CARD FAILED, OR NOT PRESENT!");
while (1); // don't do anything more:
}
Serial.println("SD CARD INITIALIZED.");
// open file for reading
file = SD.open("arduino.txt", FILE_READ);
if (file)
file.close();
else
Serial.print("SD Card: error on opening file");
}
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 .