Class SdFatFile¶
Description
Defines a class of SD FAT File.
Members
Public Constructors |
|
---|---|
SdFatFile::SdFatFile |
Constructs a SdFatFile object |
SdFatFile::~SdFatFile |
Destructs a SdFatFile object |
Public Methods |
|
SdFatFile::write |
Write 1 byte/bytes to file |
SdFatFile::read |
Read 1 byte/bytes from the file |
SdFatFile::peek |
Read 1 byte from file without move curser |
SdFatFile::available |
Check if the cursor is at EOF (End-Of-File) |
SdFatFile::bool |
Check if file is opened |
SdFatFile::seek |
Change cursor to a specific position |
SdFatFile::close |
Close file |
SdFatFile::write
SdFatFile:: read
Example Code
#include 「FatFs_SD.h」
char dirname[] = 「testdir」;
char filename[] = 「test.txt」;
char write_content[] = 「hello world!」;
FatFsSD fs;
void setup() {
char buf[128];
char absolute_filename[128];
fs.begin();
sprintf(absolute_filename, 「%s%s」, fs.getRootPath(), dirname);
fs.mkdir(absolute_filename);
printf(「create dir at \」%s"rn」, absolute_filename);
sprintf(absolute_filename, 「%s%s/%s」, fs.getRootPath(), dirname, filename);
SdFatFile file = fs.open(absolute_filename);
file.println(write_content);
file.close();
printf(「create file at \」%s"rn」, absolute_filename);
printf(「read back from \」%s"rn」, absolute_filename);
file = fs.open(absolute_filename);
memset(buf, 0, sizeof(buf));
file.read(buf, sizeof(buf));
file.close();
printf(「==== content ====rn」);
printf(「%s」, buf);
printf(「==== end ====rn」);
fs.end();
}
void loop() {
delay(1000);
}
#include 「FatFs_SD.h」
char filename[] = 「test.txt」;
char write_content[] = 「hello world!」;
FatFsSD fs;
void setup() {
char buf[128];
char absolute_filename[128];
fs.begin();
printf(「write something to \」%s"rn」, filename);
sprintf(absolute_filename, 「%s%s」, fs.getRootPath(), filename);
SdFatFile file = fs.open(absolute_filename);
file.println(write_content);
file.close();
printf(「write finishrnrn」);
printf(「read back from \」%s"rn」, filename);
file = fs.open(absolute_filename);
memset(buf, 0, sizeof(buf));
file.read(buf, sizeof(buf));
file.close();
printf(「==== content ====rn」);
printf(「%s」, buf);
printf(「==== end ====rn」);
fs.end();
}
void loop() {
delay(1000);
}
SdFatFile:: peek
SdFatFile:: available
SdFatFile:: flush
SdFatFile:: seek
SdFatFile:: close
#include <FatFs_SD.h>
FatFsSD fs;
char filename[] = 「test.txt」;
void setup() {
char absolute_filename[128];
uint16_t year = 2021;
uint16_t month = 4;
uint16_t date = 4;
uint16_t hour = 12;
uint16_t minute = 12;
uint16_t second = 12;
fs.begin();
sprintf(absolute_filename, 「%s%s」, fs.getRootPath(), filename);
SdFatFile file = fs.open(absolute_filename);
file.close();
fs.setLastModTime(absolute_filename, year, month, date, hour, minute, second);
fs.getLastModTime(absolute_filename, &year, &month, &date, &hour, &minute, &second);
printf(「filename:"%s"rn」, absolute_filename);
printf(「time mod:%04d/%02d/%02d %02d:%02d:%02drn」, year, month, date, hour, minute, second);
fs.end();
}
void loop() {
delay(1000);
}