写内容
#include <SPIFFS.h> void setup() { Serial.begin(115200); if (!SPIFFS.begin(true)) { Serial.println("SPIFFS mount failed"); return; } File file = SPIFFS.open("/xiaohe.txt", "w"); if (!file) { Serial.println("File open failed"); return; } file.println("Hello, SPIFFS! QQ496631085"); file.close(); Serial.println("File written successfully"); } void loop() { // Your code here }
读内容
#include <SPIFFS.h> void setup() { Serial.begin(115200); if (!SPIFFS.begin()) { // 初始化SPIFFS文件系统 Serial.println("SPIFFS加载错误!"); return; } // 列出文件列表 File root = SPIFFS.open("/"); File file = root.openNextFile(); while (file) { Serial.print("文件: "); Serial.println(file.name()); file = root.openNextFile(); } // 读取文件内容 File readFile = SPIFFS.open("/xiaohe.txt", "r"); if (readFile) { Serial.println("文件内容:"); while (readFile.available()) { Serial.write(readFile.read()); } readFile.close(); } else { Serial.println("文件打开失败"); } } void loop() { // Your code here }