ファイルに書き込みたい

File file = LittleFS.open(path, FILE_WRITE);
file.print("message");
file.close();

write_fileしたい

#include <LittleFs.h>

void write_file(const char *path, const char *message) {
    File file = LittleFS.open(path, FILE_WRITE);
    if (!file) {
        Serial.println("Failed to open file for writing");
        return;
    }

    if (file.print(message)) {
        Serial.println("File written");
    } else {
        Serial.println("Write failed");
    }
    file.close();
}

void setup() {
    LittleFS.begin();
    write_file("/config.txt", "Hello, World");
}

void loop() {}

append_fileしたい

 1#include <LittleFS.h>
 2
 3void appendFile(const char *path, const char *message) {
 4    File file = LittleFS.open(path, FILE_APPEND);
 5    if (!file) {
 6        Serial.println("Failed to open file for appending");
 7        return;
 8    }
 9    if (file.print(message)) {
10        Serial.println("Message appended");
11    } else {
12        Serial.println("Append failed");
13    }
14    file.close();
15}
16
17void setup() {
18    LittleFS.begin();
19    appendFile("/log.txt", "New log entry\n");
20}
21
22void loop() {}